Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After upgrade to Spring Boot v2.1.0 Consul auto registration not working #464

Closed
devpreview opened this issue Nov 7, 2018 · 10 comments
Closed

Comments

@devpreview
Copy link
Contributor

devpreview commented Nov 7, 2018

After upgrade to Spring Boot v2.1.0 Consul auto registration not working.

Minimal step repo for Spring Boot v2.0.6
https://github.com/devpreview/test-consul/tree/spring-v2.0.6

It works correctly.

2018-11-07 20:55:40.179 INFO 17032 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2018-11-07 20:55:40.195 INFO 17032 --- [ main] o.s.c.c.s.ConsulServiceRegistry : Registering service with consul: NewService{id='test-6f583ab5b29c271d1d1cd52a34e86c58', name='test', tags=[secure=false], address='sabo-probook.lan', port=8080, enableTagOverride=null, check=Check{script='null', interval='10s', ttl='null', http='http://sabo-probook.lan:8080/actuator/health', tcp='null', timeout='null', deregisterCriticalServiceAfter='null', tlsSkipVerify=null, status='null'}, checks=null}
2018-11-07 20:55:40.232 INFO 17032 --- [ main] com.test.consul.Application : Started Application in 4.385 seconds (JVM running for 5.636)

Minimal step repo for Spring Boot v2.1.0
https://github.com/devpreview/test-consul/tree/spring-v2.1.0

Consul auto registration not working.

2018-11-07 20:58:06.135 INFO 17631 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2018-11-07 20:58:06.136 INFO 17631 --- [ main] com.test.consul.Application : Started Application in 2.301 seconds (JVM running for 2.91)

  • Spring Boot version: 2.1.0
  • Spring Cloud version: Finchley.SR2
  • Java version: OpenJDK 9.0.4
  • OS: Linux
@devpreview
Copy link
Contributor Author

As hotfix you may starting registration manually:

@Configuration
public class ConsulConfiguration {
    @Bean
    public ApplicationListener<ApplicationReadyEvent> consulServiceRegistryRegister(ConsulAutoServiceRegistration consulAutoServiceRegistration) {
        return event -> {
            consulAutoServiceRegistration.setPort(8080);
            consulAutoServiceRegistration.start();
        };
    }
}

@spencergibb
Copy link
Member

Finchley is not compatible with boot 2.1.x

@jdkhome
Copy link

jdkhome commented Dec 13, 2018

As hotfix you may starting registration manually:

@Configuration
public class ConsulConfiguration {
    @Bean
    public ApplicationListener<ApplicationReadyEvent> consulServiceRegistryRegister(ConsulAutoServiceRegistration consulAutoServiceRegistration) {
        return event -> {
            consulAutoServiceRegistration.setPort(8080);
            consulAutoServiceRegistration.start();
        };
    }
}

thanks! you can comment out consulAutoServiceRegistration.setPort(8080);

@devpreview
Copy link
Contributor Author

devpreview commented Dec 13, 2018

@jdkhome If you not set port on ConsulAutoServiceRegistration you will get an exception:

java.lang.IllegalArgumentException: service.port has not been set
	at org.springframework.util.Assert.notNull(Assert.java:198)
	at org.springframework.cloud.consul.serviceregistry.ConsulAutoServiceRegistration.getRegistration(ConsulAutoServiceRegistration.java:56)

See: https://github.com/spring-cloud/spring-cloud-consul/blob/master/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistration.java#L51

ConsulAutoServiceRegistration.setPort should be equal your server.port property (or your service port).

You can get port number from ServerProperties:

    @Bean
    public ApplicationListener<ApplicationReadyEvent> consulServiceRegistryRegister(
            ConsulAutoServiceRegistration consulAutoServiceRegistration,
            ServerProperties serverProperties
    ) {
        return event -> {
            consulAutoServiceRegistration.setPort(serverProperties.getPort());
            consulAutoServiceRegistration.start();
        };
    }

@spencergibb
Copy link
Member

is this still a problem with Boot 2.1.1.RELEASE and Greenwich.RC1?

@devpreview
Copy link
Contributor Author

Yes. With Boot 2.1.1.RELEASE and Greenwich.RC1 Consul auto registration does not work.

@spencergibb
Copy link
Member

spencergibb commented Dec 13, 2018

@devpreview I just created a minimal application from start.spring.io that auto registers just fine.

image

Also, your app, updated to boot 2.1.1.RELEASE and java 8 (since I don't have 9) auto registered just fine. I also set spring.application.name=testconsulautoreggh464

image

@devpreview
Copy link
Contributor Author

@spencergibb Sorry. I did not test correctly.

With Boot 2.1.1.RELEASE and Greenwich.RC1 Consul auto registration is working.

@spencergibb
Copy link
Member

Thanks for following up

@jdkhome
Copy link

jdkhome commented Jan 12, 2019

@spencergibb Sorry. I did not test correctly.

With Boot 2.1.1.RELEASE and Greenwich.RC1 Consul auto registration is working.

I upgraded to 2.1.1.RELEASE ,But if you don't use your code, auto registration is not working.
I use jdk11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants