org.zodiac.autoconfigure.bootstrap.discovery.reactive.AbstractReactiveAppDiscoveryClientConfiguration Maven / Gradle / Ivy
package org.zodiac.autoconfigure.bootstrap.discovery.reactive;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.zodiac.autoconfigure.bootstrap.discovery.simple.reactive.SimpleReactiveAppDiscoveryProperties;
import org.zodiac.commons.constants.Constants;
import org.zodiac.commons.util.Networks;
import org.zodiac.core.bootstrap.discovery.ReactiveAppDiscoveryClient;
import org.zodiac.core.bootstrap.discovery.simple.reactive.SimpleAppReactiveDiscoveryClient;
public abstract class AbstractReactiveAppDiscoveryClientConfiguration {
@Autowired(required = false)
private ServerProperties server;
@Value("${spring.application.name:application}")
private String serviceId;
private int port = 0;
private SimpleReactiveAppDiscoveryProperties simple = new SimpleReactiveAppDiscoveryProperties();
protected SimpleReactiveAppDiscoveryProperties simpleReactiveDiscoveryProperties() {
simple.getLocal().setAppServiceId(serviceId);
simple.getLocal().setAppHost(Networks.LOCAL_HOSTNAME);
simple.getLocal().setAppPort(findPort());
return simple;
}
protected ReactiveAppDiscoveryClient simpleReactiveDiscoveryClient() {
return new SimpleAppReactiveDiscoveryClient(simpleReactiveDiscoveryProperties());
}
protected int getPort() {
return port;
}
protected void setPort(int port) {
this.port = port;
}
protected SimpleReactiveAppDiscoveryProperties getSimple() {
return simple;
}
private int findPort() {
if (port > 0) {
return port;
}
if (server != null && server.getPort() != null && server.getPort() > 0) {
return server.getPort();
}
return Constants.Spring.DEFAULT_SERVER_PORT_NUMBER;
}
}