Ole
Ole

Reputation: 46960

Does Netflix Eureka support dynamically named Spring Boot applications?

Per this article Netflix's Eureka service registry supports registering named services using the property spring.application.name. For example:

spring.application.name=a-eureka-client

Does Spring-Boot/Eureka support having dynamic names based on perhaps a templating pattern like:

spring.application.name=a-eureka-client-####

Thus the first two instances deployed would be registered as:

 a-eureka-client-0001
 a-eureka-client-0002

Upvotes: 0

Views: 1026

Answers (3)

Meow Cat 2012
Meow Cat 2012

Reputation: 998

Apart from command line or through environment variables, it is also possible to set it programmatically in Java when necessary, e.g. automatically append the host's id.

In <SomeName>Application.java (or ServletInitializer.java when using container like Tomcat):

// ...
public static void main(String[] args) {
        // add this line
        System.setProperty("spring.application.name", "some dynamatically generated name");
        SpringApplication.run(<SomeName>Application.class, args);

Upvotes: 0

vimal krishna
vimal krishna

Reputation: 2966

if you are using spring boot then in src/main/resources folder you have to have extra bootstrap.properties file, and line line below. Don't put in application.properties file.

spring.application.name=Car-Position-Tracker

bootstrap.properties file is read while application context is being loaded: See Reference manual of Spring-cloud

and to be picked up add Build plugin in POM, which is by *.properties

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>

    <resources>
        <resource>
            <filtering>true</filtering>
            <directory>src/main/resources</directory>
            <includes>
                <include>*.properties</include>
            </includes>
        </resource>     
    </resources>        
</build>

Upvotes: 0

Kartik Pandya
Kartik Pandya

Reputation: 2898

You could pass spring.application.name property via command line or through environment variables as shown below:

$ java -jar app.jar --spring.applocation.name=a-eureka-client-001

Or

$ export SPRING_APPLICATION_NAME=a-eureka-client-002

$ java -jar app.jar

Alternatively, you can come up with a custom property called my.app.suffix, inject that as a command line property or environment variable as shown above, and in your application.properties (or YML), use the suffix to complete the name of your application:

spring.application.name: a-eureka-client-${my.app.suffix:some-default}

That way, you can support a case when the suffix is not provided, in which case some-default will be used as the suffix by default.

Upvotes: 1

Related Questions