A, requirements,

When our project is released, if we use Eureka in our registry, when we have multiple service instances, we want to achieve a smooth release when publishing a service, without errors in the service invocation process.

Eg: For example, we have two goods and services, when we release, we first send instance A, and then send instance B. Suppose we want to send instance A first. If there are requests being processed on instance A, we need to complete the normal processing. When there is no traffic coming into instance A, we need to shut down instance A and restart instance A.

Two, implementation steps

1. Use Eureka’s REST API to query the list of services

Send a GET request to access /eureka/apps

curl --location --request GET 'http://localhost:8761/eureka/apps' \
--header 'Accept: Application/json' \
--header 'the user-agent: apifox / 1.0.0 (https://www.apifox.cn)'
Copy the code

Use Eureka’s REST API to mark the state of the service asDOWN.

> < p style = "margin-bottom: 0pt; margin-bottom: 0pt; > When the next Eureka client pulls the list of available services from the Eureka server, the down service is not pulled. > In this case, you may need to wait for a certain amount of time (eureka.client.registrie-fetch -interval-second=30 + a certain amount of service processing time) and then perform Step 3 to ensure that all tasks on the machine are completed. The service can be shut down without incoming traffic. > Instead of performing the DELETE /appId/instanceId request, downgrade the service from the Eureka server. If processing is slow, the service may be registered with the Eureka server again in the next heartbeat.Copy the code

Send a PUT request, access/had been/apps/appId/instanceId/status? Value = “DOWN.

  • AppId See appId in the figure above
  • InstanceId See instanceId in the figure above
  • value=[DOWN | UP] DOWNFlag service unavailable,UPTag services are available.
curl --location --request PUT 'http://localhost:8761/eureka/apps/PRODUCT-PROVIDER/product-provider:192.168.0.85:8083/status? value=DOWN' \
--header 'Accept: Application/json' \
--header 'the user-agent: apifox / 1.0.0 (https://www.apifox.cn)'
Copy the code

3. Shut down and start the service

Close: kill -15 PID start: Java -jar xxx.java and so on

Eureka REST API

4. Reference links

1, github.com/Netflix/eur…