自定义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
相关推荐
若亦_Royi几秒前
C++ 的大括号的用法合集
开发语言·c++
资源补给站1 小时前
大恒相机开发(2)—Python软触发调用采集图像
开发语言·python·数码相机
豪宇刘1 小时前
MyBatis的面试题以及详细解答二
java·servlet·tomcat
秋恬意1 小时前
Mybatis能执行一对一、一对多的关联查询吗?都有哪些实现方式,以及它们之间的区别
java·数据库·mybatis
m0_748247551 小时前
Web 应用项目开发全流程解析与实战经验分享
开发语言·前端·php
6.942 小时前
Scala学习记录 递归调用 练习
开发语言·学习·scala
FF在路上2 小时前
Knife4j调试实体类传参扁平化模式修改:default-flat-param-object: true
java·开发语言
真的很上进2 小时前
如何借助 Babel+TS+ESLint 构建现代 JS 工程环境?
java·前端·javascript·css·react.js·vue·html
众拾达人3 小时前
Android自动化测试实战 Java篇 主流工具 框架 脚本
android·java·开发语言
皓木.3 小时前
Mybatis-Plus
java·开发语言