自定义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
相关推荐
爱喝醋的雷达6 分钟前
Spring SpringBoot 细节总结
java·spring boot·spring
不知名。。。。。。。。14 分钟前
C++__list
开发语言·c++·list
EverestVIP43 分钟前
C++动态库对外接口通过接口方式实现
开发语言·c++
Swift社区1 小时前
Swift LeetCode 246 题解:中心对称数(Strobogrammatic Number)
开发语言·leetcode·swift
coderzpw1 小时前
当模板方法模式遇上工厂模式:一道优雅的烹饪架构设计
java·模板方法模式
巷北夜未央1 小时前
Python每日一题(13)
开发语言·python·算法
直裾1 小时前
Mapreduce初使用
java·mapreduce
woniu_maggie1 小时前
SAP EXCEL DOI 详解
开发语言·后端·excel
小爬虫程序猿1 小时前
利用 PHP 爬虫按关键字搜索淘宝商品
开发语言·爬虫·php
悠夏安末1 小时前
intellij Idea 和 dataGrip下载和安装教程
java·ide·intellij-idea