Skip to content

将注册中心Erueka改为Zookeeper后,HystrixStreamTask报空指针异常 #9

Description

@dengly

错误信息如下

2018-09-27 13:45:40.446 ERROR 39215 --- [ask-scheduler-5] o.s.c.n.h.stream.HystrixStreamTask       : Error adding metrics to queue

java.lang.NullPointerException: null
	at org.springframework.cloud.netflix.hystrix.stream.HystrixStreamTask.addServiceData(HystrixStreamTask.java:377)
	at org.springframework.cloud.netflix.hystrix.stream.HystrixStreamTask.gatherMetrics(HystrixStreamTask.java:134)
	at sun.reflect.GeneratedMethodAccessor190.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
	at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.runAndReset$$$capture(FutureTask.java:308)
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:748)

经过调试发现在org.springframework.cloud.netflix.hystrix.stream.HystrixStreamTask中的addServiceData方法报错来的,原因是this.discoveryClient.getLocalServiceInstance()null,而this.discoveryClient的类型是org.springframework.cloud.zookeeper.discovery.ZookeeperDiscoveryClientZookeeperDiscoveryClientgetLocalServiceInstance()(代码如下)返回是null

public ServiceInstance getLocalServiceInstance() {
        if (this.zookeeperServiceDiscovery == null) {
            return null;
        } else {
            org.apache.curator.x.discovery.ServiceInstance<ZookeeperInstance> serviceInstance = (org.apache.curator.x.discovery.ServiceInstance)this.zookeeperServiceDiscovery.getServiceInstanceRef().get();
            return serviceInstance == null ? null : createServiceInstance(serviceInstance.getName(), serviceInstance);
        }
    }

调试发现走了else部分,(org.apache.curator.x.discovery.ServiceInstance)this.zookeeperServiceDiscovery.getServiceInstanceRef().get()返回值是null。目前还没找到解决方案。

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions