All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.feingto.cloud.config.consul.ConsulServiceAutoRegistration Maven / Gradle / Ivy

The newest version!
package com.feingto.cloud.config.consul;

import com.ecwid.consul.v1.ConsulClient;
import org.springframework.cloud.client.serviceregistry.ServiceRegistry;
import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties;
import org.springframework.cloud.consul.discovery.HeartbeatProperties;
import org.springframework.cloud.consul.discovery.TtlScheduler;
import org.springframework.cloud.consul.serviceregistry.ConsulRegistration;
import org.springframework.cloud.consul.serviceregistry.ConsulServiceRegistry;

/**
 * Consul 服务自动注册
 *
 * @author longfei
 */
@SuppressWarnings("unchecked")
public class ConsulServiceAutoRegistration extends ConsulServiceRegistry implements ServiceRegistry {
    public ConsulServiceAutoRegistration(ConsulClient client, ConsulDiscoveryProperties properties,
                                         TtlScheduler ttlScheduler, HeartbeatProperties heartbeatProperties) {
        super(client, properties, ttlScheduler, heartbeatProperties);
    }

    @Override
    public void register(ConsulRegistration reg) {
        reg.getService().setId(reg.getService().getName()
                .concat("-")
                .concat(reg.getService().getAddress())
                .concat(":")
                .concat(String.valueOf(reg.getPort())));
        super.register(reg);
    }

    @Override
    public String getStatus(ConsulRegistration registration) {
        return String.valueOf(super.getStatus(registration));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy