自定义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
相关推荐
奋斗的小花生3 分钟前
c++ 多态性
开发语言·c++
魔道不误砍柴功5 分钟前
Java 中如何巧妙应用 Function 让方法复用性更强
java·开发语言·python
NiNg_1_2345 分钟前
SpringBoot整合SpringSecurity实现密码加密解密、登录认证退出功能
java·spring boot·后端
闲晨8 分钟前
C++ 继承:代码传承的魔法棒,开启奇幻编程之旅
java·c语言·开发语言·c++·经验分享
老猿讲编程36 分钟前
一个例子来说明Ada语言的实时性支持
开发语言·ada
Chrikk2 小时前
Go-性能调优实战案例
开发语言·后端·golang
幼儿园老大*2 小时前
Go的环境搭建以及GoLand安装教程
开发语言·经验分享·后端·golang·go
canyuemanyue2 小时前
go语言连续监控事件并回调处理
开发语言·后端·golang
杜杜的man2 小时前
【go从零单排】go语言中的指针
开发语言·后端·golang
测开小菜鸟2 小时前
使用python向钉钉群聊发送消息
java·python·钉钉