spring-cloud / spring-cloud-netflix

Integration with Netflix OSS components
http://cloud.spring.io/spring-cloud-netflix/
Apache License 2.0
4.86k stars 2.44k forks source link

Publish custom port to eureka service registry from eureka client #4056

Open an0nh4x0r opened 2 years ago

an0nh4x0r commented 2 years ago

Eureka client by default publishes ${server.port} to service registery i.e. eureka server. There needs to be a property where we can publish custom port to service registry

There needs to be a property called ${eureka.instance.custom-port} which can be used to set custom port which will then get published to the eureka server ... instead of ${server.port}

In my organization , I've override a bean called eurekaInstanceConfigBean basically at this line here in class EurekaClientAutoConfiguration I'm checking for custom port property and if it's present I'm using custom port instead of ${server.port} and publishing that port instead. It works great for me

I would like to get this property support officially from the library

OlgaMaciaszek commented 2 years ago

Hello @an0nh4x0r, why do you need this functionality? Could you describe your use-case in more details?

an0nh4x0r commented 2 years ago

Hey @OlgaMaciaszek ... We have our own cloud in my company where we run custom built containers(not docker) ... We basically have two ports i.e. first inner port of which spring boot is running, second outer port through which traffic gets port forwarded to this inner port in which spring boot app runs ... I have access to outer port number in container through enviornment variable ... I was looking for ways to publish this outer port to eureka service registery. In my company I see people who are using zookeeper as service registery have option to publish custom port to zookeeper ... I was looking to get same functionality natively from Eureka client.

OlgaMaciaszek commented 2 years ago

@an0nh4x0r thanks for the details. Will discuss it with the team and get back to you.

OlgaMaciaszek commented 2 years ago

@an0nh4x0r Actually, you should be able to set it using these props. Let me know if this solves your issue.

spring-cloud-issues commented 2 years ago

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-cloud-issues commented 2 years ago

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

madmurl0c commented 9 months ago

I am not the original creator of this issue but I'm experiencing a similar issue.

Here's the required part of my application.yml:

eureka:
    instance:
        hostname: ${EUREKA_HOSTNAME:localhost}
        securePort: ${EUREKA_PORT:443}
server:
    port: '443'
    http:
        port: '80'

I want spring to use the default ports for http/https inside of docker (easier integration into out stacks) but eureka should advertise the "external" port.

Since this didn't have the effect I wanted I tried it like this:

@Value("${eureka.instance.securePort}")
private int eurekaInstanceSecurePort;

@Bean
public EurekaInstanceConfigBean eurekaInstanceConfig(InetUtils inetUtils) {
    EurekaInstanceConfigBean bean = new EurekaInstanceConfigBean(inetUtils);
    System.out.println("Override port: " + eurekaInstanceSecurePort);
    bean.setSecurePortEnabled(true);
    bean.setSecurePort(eurekaInstanceSecurePort);
    return bean;
}

If I use this command docker run -p 30001:443 -e EUREKA_PORT=30001 -e EUREKA_HOSTNAME=server01 ... eureka still reports the port 443 and not 30001.

The log looks like this:

Override port: 30001
...
EurekaAutoServiceRegistration : Updating port to 443

If you need any more info please let me know