spring-cloud / spring-cloud-consul

Spring Cloud Consul
http://cloud.spring.io/spring-cloud-consul/
Apache License 2.0
813 stars 541 forks source link

ConsulDiscoveryClient can't get bean ConsulRegistration and ConsulLifecycle in application context. #306

Closed cuizuoli closed 5 years ago

cuizuoli commented 7 years ago

After upgraded Spring Cloud Dalston.RELEASE and spring-cloud-consul-discovery(1.2.0.RELEASE), HystrixStreamTask occurs error:

2017-05-03 17:27:45,302 ERROR task-scheduler-8 o.s.c.n.h.s.HystrixStreamTask:368 - Error adding metrics to queue
java.lang.IllegalStateException: Must have one of ConsulRegistration or ConsulLifecycle
    at org.springframework.cloud.consul.discovery.ConsulDiscoveryClientConfiguration$LifecycleRegistrationResolver.getInstanceId(ConsulDiscoveryClientConfiguration.java:95) ~[spring-cloud-consul-discovery-1.2.0.RELEASE.jar:1.2.0.RELEASE]
    at org.springframework.cloud.consul.discovery.ConsulDiscoveryClient.getLocalServiceInstance(ConsulDiscoveryClient.java:95) ~[spring-cloud-consul-discovery-1.2.0.RELEASE.jar:1.2.0.RELEASE]
    at org.springframework.cloud.netflix.hystrix.stream.HystrixStreamTask.gatherMetrics(HystrixStreamTask.java:120) ~[spring-cloud-netflix-hystrix-stream-1.3.0.RELEASE.jar:1.3.0.RELEASE]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_45]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_45]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_45]
    at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_45]
    at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65) [spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) [spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_45]
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [na:1.8.0_45]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_45]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [na:1.8.0_45]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_45]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_45]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_45]

When I used maunally spring-cloud-consul-discovery(1.1.2.RELEASE), it's ok.

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-consul-discovery</artifactId>
    <version>1.1.2.RELEASE</version>
</dependency>

I found that there isn't ConsulRegistration and ConsulLifecycle bean in application context.

https://github.com/spring-cloud/spring-cloud-consul/commits/master/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulDiscoveryClientConfiguration.java

@Override
public String getInstanceId() {
    ConsulRegistration registration = getBean(ConsulRegistration.class);
    if (registration != null) {
        return registration.getInstanceId();
    }
    ConsulLifecycle lifecycle = getBean(ConsulLifecycle.class);
    if (lifecycle != null) {
        return lifecycle.getInstanceId();
    }
    throw new IllegalStateException("Must have one of ConsulRegistration or ConsulLifecycle");
}

I don't known that why there aren't ConsulRegistration and ConsulLifecycle in application context. when I access /beans api, ConsulRegistration and ConsulLifecycle exists in response.

Regards,

Eren

spencergibb commented 7 years ago

Can you provide a simple project that recreates the problem?

cuizuoli commented 7 years ago

Thank you for your help, Please refer to spring-cloud-feedback in my github.

spencergibb commented 7 years ago

Any instructions on how to replicate the bug? I'm unable to replicate the issue with your project.

cuizuoli commented 7 years ago

Please refer to readme file.

First, you have to configuration kafka and consul.

keets2012 commented 7 years ago

have you fixed the bug?

spencergibb commented 7 years ago

@keets2012 no

spencergibb commented 7 years ago

It's likely a similar problem to https://github.com/spring-cloud/spring-cloud-netflix/issues/2083. Ie, not a problem here, but turbine causing early initialization.

spencergibb commented 6 years ago

@cuizuoli or @keets2012 is this still an issue?

spencergibb commented 5 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.