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

Spring Cloud ZooKeeper Discovery Client Not Register on ZooKeeper when using SpringBootServletInitializer #158

Open
xiangyq000 opened this issue Jan 25, 2018 · 13 comments

Comments

@xiangyq000
Copy link

I have a spring boot application that use spring-cloud-stater-zookeeper-discovery to register the service, but it doesn't work.

  1. the application is deployed as a WAR.

     @SpringBootConfiguration
     @EnableAutoConfiguration
     @EnableDiscoveryClient
     public class MyApplication extends SpringBootServletInitializer {
     
         @Override
         protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
             return application.sources(MyApplication.class)
                     .properties("spring.cloud.zookeeper.discovery.instance-host=" + getHostName())
                     .web(true);
         }
     }
     
  2. the application has connected to the zookeeper instance. Ping messages to zookeeper can be seen in the application's log and the output of STAT command shows a connected zookeeper client.

  3. the application does not register watchers to appointed zookeeper path, i.e., /services. This can be confirmed by sending WCHC command to the zookeeper.

Spring Boot version: 1.5.9

spring-cloud-stater-zookeeper-discovery: 1.2.0.RELEASE

web container: tomcat 8.5.23

@xiangyq000 xiangyq000 changed the title Spring Cloud ZooKeeper Discovery Client Does Not Register on ZooKeeper Spring Cloud ZooKeeper Discovery Client Not Register on ZooKeeper when using SpringBootServletInitializer Jan 26, 2018
@spencergibb
Copy link
Member

There is a similar problem in consul

@iurii-dziuban-onpex
Copy link

Any workaround on this?

@spencergibb
Copy link
Member

Maybe

	@EventListener(ApplicationStartedEvent.class)
	public void init(ApplicationStartedEvent event) {
		ConfigurableApplicationContext context = event.getApplicationContext();
		ZookeeperRegistration registration = context.getBean(ZookeeperRegistration.class);
		registration.setPort(9080);
		ZookeeperAutoServiceRegistration serviceRegistration = context.getBean(ZookeeperAutoServiceRegistration.class);
		serviceRegistration.start();
	}

@rodoc81
Copy link

rodoc81 commented Nov 5, 2018

I got the same issue with newer version:

  • Spring Boot version: 2.1.0.RELEASE
  • spring-cloud-stater-zookeeper-discovery: 2.1.0.M1
  • web container: tomcat 8.5.34

I used suggested solution above by @spencergibb . I'm using properties to set the port so don't need the first part.

@Autowired
private ZookeeperAutoServiceRegistration serviceRegistration;

@EventListener(ApplicationStartedEvent.class)
public void init(final ApplicationStartedEvent event) {
    serviceRegistration.start();
}

@nicqchen
Copy link

I have same issues, any one could help on this?

@nicqchen
Copy link

nicqchen commented Jan 24, 2019

2019-01-24 07:15:43.006 ERROR 1 --- [nStateManager-0] o.a.c.x.d.details.ServiceDiscoveryImpl   : Could not re-register instances after reconnection

java.lang.IllegalStateException: instance must be started before calling this method
        at org.apache.curator.shaded.com.google.common.base.Preconditions.checkState(Preconditions.java:444) ~[curator-client-4.0.1.jar!/:na]
        at org.apache.curator.framework.imps.CuratorFrameworkImpl.create(CuratorFrameworkImpl.java:416) ~[curator-framework-4.0.1.jar!/:4.0.1]
        at org.apache.curator.x.discovery.details.ServiceDiscoveryImpl.internalRegisterService(ServiceDiscoveryImpl.java:236) ~[curator-x-discovery-4.0.1.jar!/:na]
        at org.apache.curator.x.discovery.details.ServiceDiscoveryImpl.reRegisterServices(ServiceDiscoveryImpl.java:456) ~[curator-x-discovery-4.0.1.jar!/:na]
        at org.apache.curator.x.discovery.details.ServiceDiscoveryImpl.access$100(ServiceDiscoveryImpl.java:58) ~[curator-x-discovery-4.0.1.jar!/:na]
        at org.apache.curator.x.discovery.details.ServiceDiscoveryImpl$1.stateChanged(ServiceDiscoveryImpl.java:78) ~[curator-x-discovery-4.0.1.jar!/:na]
        at org.apache.curator.framework.state.ConnectionStateManager$2.apply(ConnectionStateManager.java:274) [curator-framework-4.0.1.jar!/:4.0.1]
        at org.apache.curator.framework.state.ConnectionStateManager$2.apply(ConnectionStateManager.java:270) [curator-framework-4.0.1.jar!/:4.0.1]
        at org.apache.curator.framework.listen.ListenerContainer$1.run(ListenerContainer.java:93) [curator-framework-4.0.1.jar!/:4.0.1]
        at org.apache.curator.shaded.com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:435) [curator-client-4.0.1.jar!/:na]
        at org.apache.curator.framework.listen.ListenerContainer.forEach(ListenerContainer.java:85) [curator-framework-4.0.1.jar!/:4.0.1]
        at org.apache.curator.framework.state.ConnectionStateManager.processEvents(ConnectionStateManager.java:268) [curator-framework-4.0.1.jar!/:4.0.1]
        at org.apache.curator.framework.state.ConnectionStateManager.access$000(ConnectionStateManager.java:44) [curator-framework-4.0.1.jar!/:4.0.1]
        at org.apache.curator.framework.state.ConnectionStateManager$1.call(ConnectionStateManager.java:120) [curator-framework-4.0.1.jar!/:4.0.1]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_111-internal]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_111-internal]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_111-internal]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_111-internal]

@zhuangjinjin
Copy link

it seem that problem was here in EventListenerMethodProcessor, it does't work on SpringContainerClass who annotated @EventListner

private static boolean isSpringContainerClass(Class<?> clazz) {
	return (clazz.getName().startsWith("org.springframework.") && !AnnotatedElementUtils.isAnnotated(ClassUtils.getUserClass(clazz), Component.class));
}

private void processBean(final String beanName, final Class<?> targetType) {
	if (!this.nonAnnotatedClasses.contains(targetType) && !isSpringContainerClass(targetType)) {
		...
		//context#addApplicationListener
	}
}

@venkateshzifo
Copy link

Hi,

Any update on this one ? I am facing the same issue when deploy the application as WAR.

@marcingrzejszczak
Copy link
Contributor

If there are no comments then there are no updates

@venkateshzifo
Copy link

Is there any other workaround ?

@spencergibb
Copy link
Member

spencergibb commented Sep 17, 2019

Instead of @EventListener

class MyClass implements ApplicationListener<ApplicationStartedEvent> {
  public void onApplicationEvent(ApplicationStartedEvent event) {
    serviceRegistration.start();
  }
}

@sqnczzl
Copy link

sqnczzl commented Feb 20, 2020

I have the same issuse

  • Spring Boot version: 2.1.4.RELEASE
  • spring-cloud-stater-zookeeper-discovery: 2.1.4
  • web container: tomcat 8.5.34

@weihubeats
Copy link

I also encountered a similar problem, mainly caused by the inconsistency of the ZooKeeper server and java client versions. Changing to a consistent version can solve the problem

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

No branches or pull requests

10 participants