自定义acuator端口

java 复制代码
@Component
@Endpoint(id = "nacos-deregister-instance")
public class NacosDeRegisterInstanceEndpoint {
    public static final Logger logger = LoggerFactory.getLogger(NacosDeRegisterInstanceEndpoint.class);
//    @Resource
//    private SpringClientFactory springClientFactory;

    @Resource
    private RefreshScope refreshScope;

    @Resource
    private NacosDiscoveryProperties nacosDiscoveryProperties;

    public NacosDeRegisterInstanceEndpoint(NacosDiscoveryProperties nacosDiscoveryProperties) {
        this.nacosDiscoveryProperties = nacosDiscoveryProperties;
    }

    @ReadOperation
    public String deregisterInstance() {
        String serviceName = nacosDiscoveryProperties.getService();
        String groupName = nacosDiscoveryProperties.getGroup();
        String clusterName = nacosDiscoveryProperties.getClusterName();
        String ip = nacosDiscoveryProperties.getIp();
        int port = nacosDiscoveryProperties.getPort();
        logger.info("deregister from nacos, serviceName:{}, groupName:{}, clusterName:{}, ip:{}, port:{}", serviceName, groupName, clusterName, ip, port);
        try {
            nacosDiscoveryProperties.namingServiceInstance().deregisterInstance(serviceName, groupName, ip, port, clusterName);
            refreshScope.refresh(serviceName);
        } catch (NacosException e) {
            logger.error("deregister from nacos error", e);
            return "error";
        }
        return "success";
    }

        @ConditionalOnClass(Endpoint.class)
    @ConditionalOnBean(type = "com.alibaba.cloud.nacos.NacosDiscoveryProperties")
    public class NacosDeRegisterInstanceEndpointAutoConfiguration {

        @Resource
        private NacosDiscoveryProperties nacosDiscoveryProperties;

        @ConditionalOnMissingBean
        @Bean
        public NacosDeRegisterInstanceEndpoint nacosDeRegisterEndpoint() {
            return new NacosDeRegisterInstanceEndpoint(nacosDiscoveryProperties);
        }
    }
}

服务下线

java 复制代码
management:
  endpoints:
    web:
      exposure:
        include: health,shutdown,service-registry,nacos-deregister-instance
  endpoint:
    health:
      show-details: always
    shutdown:
      enabled: true
    nacos-deregister-instance:
      enabled: true
java 复制代码
management:
  endpoints:
    web:
      exposure:
        include: health,shutdown,service-registry
      path-mapping:
        service-registry: deregister
  endpoint:
    health:
      show-details: always
    shutdown:
      enabled: true
    nacos-deregister-instance:
      enabled: true
相关推荐
小屁孩大帅-杨一凡1 分钟前
Python-flet实现个人视频播放器
开发语言·python·音视频
万琛1 分钟前
【java-Neo4j 5开发入门篇】-最新Java开发Neo4j
java·neo4j
算家云4 分钟前
快速识别模型:simple_ocr,部署教程
开发语言·人工智能·python·ocr·数字识别·检测模型·英文符号识别
Thomas_Cai15 分钟前
Python后端flask框架接收zip压缩包方法
开发语言·python·flask
霍先生的虚拟宇宙网络17 分钟前
webp 网页如何录屏?
开发语言·前端·javascript
温吞-ing19 分钟前
第十章JavaScript的应用
开发语言·javascript·ecmascript
Bald Baby20 分钟前
JWT的使用
java·笔记·学习·servlet
魔道不误砍柴功26 分钟前
实际开发中的协变与逆变案例:数据处理流水线
java·开发语言
鲤籽鲲34 分钟前
C# MethodTimer.Fody 使用详解
开发语言·c#·mfc