I am building a dockerized spring-cloud based microservice that registers with eureka. Part of the registration process is asking the host for the port mapped to the container so docker can choose a free host port for the containerized service.
I have a host based service the dockerized service can ask for the port mapping and am now trying to register the microservide with eureka using the external port.
I get the right port inside my microservice but am unable to override the EurekaInstanceConfig
.
What i have tried:
@SpringBootApplication
@EnableEurekaClient
public class ApplicationBootstrapper {
@Value("${containerIp}")
private String containerIp;
@Bean
public EurekaInstanceConfigBean eurekaInstanceConfigBean() {
EurekaInstanceConfigBean config = new EurekaInstanceConfigBean();
String hostPort = new RestTemplate().getForObject(
"http://{hostname}:7691/container/{id}/hostPort",
String.class,
containerIp,
config.getHostname());
config.setPreferIpAddress(true);
config.setIpAddress(containerIp);
config.setNonSecurePort(Integer.valueOf(hostPort));
return config;
}
My custom EurekaInstanceConfigBean
gets created but the configuration is not picked up (the service registers with its internal container port).
The question is: How do i override the EurekaInstanceConfigBean
?
Aucun commentaire:
Enregistrer un commentaire