若是直接KILL SpringCloud的服務,由於Eureka採用心跳的機制來上下線服務,會致使服務消費者調用此已經kill的服務提供者而後出錯,處理這種狀況有2中方案。html
如需平滑的發佈服務請參考:spring
1、利用Spring Boot Actuato的管理端點(推薦)緩存
一、pom中引用Actuato服務器
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
二、properties中添加以下內容curl
#啓用shutdown endpoints.shutdown.enabled=true #禁用密碼驗證 endpoints.shutdown.sensitive=false # 禁用actuator管理端鑑權 management.security.enabled=false # 開啓重啓支持 endpoints.restart.enabled=true
若是隻容許本機訪問,能夠添加以下屬性spring-boot
#(只容許本機訪問) server.address=localhost
三、在服務器上用curl發送post請求到pause.post
curl -X POST http://localhost:8080/pause
此時eurake上該服務被標記問下線,但該服務其實仍是能夠正常訪問的,當client還未及時更新本地Instances緩存時,依然不會中斷服務。當全部client都感知到該服務DOWN後就不會再往該服務發請求了。url
四、在服務器上利用curl發送shutdown命令spa
curl -X POST http://localhost:8080/shutdown 或者 curl -d "" http://localhost:8080/shutdown
2、利用Eureka的rest管理端點下線服務rest
eureka界面註冊的服務:
發送DELETE的Restfull請求
對照關係看上面的2張圖。
注意:因爲cloud服務是心跳檢測,全部在eureka進行DELETE後要快速的中止服務,不然服務可能會被從新註冊上。