Eureka
修改配置文件
bootstrap.properties1 2 3 4 5 6 7 8 9 10 11 12 13 14
| endpoints.shutdown.enabled=true
endpoints.shutdown.sensitive=false
endpoints.pause.enabled=true
endpoints.pause.sensitive=false endpoints.restart.enabled=true endpoints.restart.sensitive=false
eureka.client.registry-fetch-interval-seconds=5
ribbon.ServerListRefreshInterval=5000
|
通过http请求停止服务
#将服务下线
http://ip:port/pause
#停止服务,等价于kill
http://ip:port/shutdown
参考文章:
https://blog.csdn.net/nihao12323432/article/details/81205288
https://www.jianshu.com/p/07c2e0d59dc9
Nacos
编写Controller,通过Nacos提供的api下线服务
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| import com.alibaba.cloud.nacos.NacosDiscoveryProperties; import com.alibaba.cloud.nacos.registry.NacosRegistration; import lombok.AllArgsConstructor; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.springblade.core.tool.api.R; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;
@RestController @RequestMapping("/nacos/service") @AllArgsConstructor @Slf4j public class ShutdownController {
private NacosRegistration nacosRegistration;
private NacosDiscoveryProperties nacosDiscoveryProperties;
@SneakyThrows @DeleteMapping("/shutdown") @SuppressWarnings("all") public R shutdown() { String serviceName = nacosDiscoveryProperties.getService(); String groupName = nacosDiscoveryProperties.getGroup(); String clusterName = nacosDiscoveryProperties.getClusterName(); String ip = nacosDiscoveryProperties.getIp(); int port = nacosDiscoveryProperties.getPort(); log.info("deregister from nacos, serviceName:{}, groupName:{}, clusterName:{}, ip:{}, port:{}", serviceName, groupName, clusterName, ip, port); nacosRegistration.getNacosNamingService().deregisterInstance(serviceName, groupName, ip, port, clusterName); return R.status(true); }
}
|
通过http请求访问该接口
curl -X DELETE http://ip:port/nacos/service/shutdown
参考文章:https://nacos.io/zh-cn/docs/sdk.html