ruyi159
意心一忆
采纳率40%
2018-06-12 14:56 阅读 4.3k
已采纳

dubbo发布服务失败的问题

5

编写了一个dubbo-demo的maven项目,
运行Provider类出现如下错误:
Exception in thread "main" java.lang.IllegalStateException: Failed to register dubbo://169.254.165.91:20880/com.ruyi.dubbo.demo.DemoService?anyhost=true&application=dubbo-demo-provider&dubbo=2.6.2&generic=false&interface=com.ruyi.dubbo.demo.DemoService&methods=sayHello&pid=14868&side=provider&timestamp=1528802622329 to registry 127.0.0.1:2181, cause: Failed to register dubbo://169.254.165.91:20880/com.ruyi.dubbo.demo.DemoService?anyhost=true&application=dubbo-demo-provider&dubbo=2.6.2&generic=false&interface=com.ruyi.dubbo.demo.DemoService&methods=sayHello&pid=14868&side=provider&timestamp=1528802622329 to zookeeper zookeeper://127.0.0.1:2181/com.alibaba.dubbo.registry.RegistryService?application=dubbo-demo-provider&dubbo=2.6.2&interface=com.alibaba.dubbo.registry.RegistryService&pid=14868&qos.port=22222&timestamp=1528802622317, cause: KeeperErrorCode = ConnectionLoss
at com.alibaba.dubbo.registry.support.FailbackRegistry.register(FailbackRegistry.java:144)
at com.alibaba.dubbo.registry.integration.RegistryProtocol.register(RegistryProtocol.java:125)
at com.alibaba.dubbo.registry.integration.RegistryProtocol.export(RegistryProtocol.java:145)
at com.alibaba.dubbo.qos.protocol.QosProtocolWrapper.export(QosProtocolWrapper.java:54)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper.export(ProtocolFilterWrapper.java:98)
at com.alibaba.dubbo.rpc.protocol.ProtocolListenerWrapper.export(ProtocolListenerWrapper.java:55)
at com.alibaba.dubbo.rpc.Protocol$Adaptive.export(Protocol$Adaptive.java)
at com.alibaba.dubbo.config.ServiceConfig.doExportUrlsFor1Protocol(ServiceConfig.java:506)
at com.alibaba.dubbo.config.ServiceConfig.doExportUrls(ServiceConfig.java:358)
at com.alibaba.dubbo.config.ServiceConfig.doExport(ServiceConfig.java:317)
at com.alibaba.dubbo.config.ServiceConfig.export(ServiceConfig.java:216)
at com.alibaba.dubbo.config.spring.ServiceBean.onApplicationEvent(ServiceBean.java:123)
at com.alibaba.dubbo.config.spring.ServiceBean.onApplicationEvent(ServiceBean.java:49)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:383)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:337)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:882)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:545)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:93)
at com.ruyi.dubbo.demo.provider.Provider.main(Provider.java:19)
Caused by: com.alibaba.dubbo.rpc.RpcException: Failed to register dubbo://169.254.165.91:20880/com.ruyi.dubbo.demo.DemoService?anyhost=true&application=dubbo-demo-provider&dubbo=2.6.2&generic=false&interface=com.ruyi.dubbo.demo.DemoService&methods=sayHello&pid=14868&side=provider&timestamp=1528802622329 to zookeeper zookeeper://127.0.0.1:2181/com.alibaba.dubbo.registry.RegistryService?application=dubbo-demo-provider&dubbo=2.6.2&interface=com.alibaba.dubbo.registry.RegistryService&pid=14868&qos.port=22222&timestamp=1528802622317, cause: KeeperErrorCode = ConnectionLoss
at com.alibaba.dubbo.registry.zookeeper.ZookeeperRegistry.doRegister(ZookeeperRegistry.java:116)
at com.alibaba.dubbo.registry.support.FailbackRegistry.register(FailbackRegistry.java:131)
... 21 more
Caused by: java.lang.IllegalStateException: KeeperErrorCode = ConnectionLoss
at com.alibaba.dubbo.remoting.zookeeper.curator.CuratorZookeeperClient.createPersistent(CuratorZookeeperClient.java:79)
at com.alibaba.dubbo.remoting.zookeeper.support.AbstractZookeeperClient.create(AbstractZookeeperClient.java:65)
at com.alibaba.dubbo.remoting.zookeeper.support.AbstractZookeeperClient.create(AbstractZookeeperClient.java:59)
at com.alibaba.dubbo.remoting.zookeeper.support.AbstractZookeeperClient.create(AbstractZookeeperClient.java:59)
at com.alibaba.dubbo.remoting.zookeeper.support.AbstractZookeeperClient.create(AbstractZookeeperClient.java:59)
at com.alibaba.dubbo.registry.zookeeper.ZookeeperRegistry.doRegister(ZookeeperRegistry.java:114)
... 22 more
Caused by: org.apache.curator.CuratorConnectionLossException: KeeperErrorCode = ConnectionLoss
at org.apache.curator.ConnectionState.checkTimeouts(ConnectionState.java:225)
at org.apache.curator.ConnectionState.getZooKeeper(ConnectionState.java:94)
at org.apache.curator.CuratorZookeeperClient.getZooKeeper(CuratorZookeeperClient.java:117)
at org.apache.curator.framework.imps.CuratorFrameworkImpl.getZooKeeper(CuratorFrameworkImpl.java:489)
at org.apache.curator.framework.imps.CreateBuilderImpl$11.call(CreateBuilderImpl.java:740)
at org.apache.curator.framework.imps.CreateBuilderImpl$11.call(CreateBuilderImpl.java:723)
at org.apache.curator.RetryLoop.callWithRetry(RetryLoop.java:109)
at org.apache.curator.framework.imps.CreateBuilderImpl.pathInForeground(CreateBuilderImpl.java:720)
at org.apache.curator.framework.imps.CreateBuilderImpl.protectedPathInForeground(CreateBuilderImpl.java:484)
at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:474)
at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:454)
at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:44)
at com.alibaba.dubbo.remoting.zookeeper.curator.CuratorZookeeperClient.createPersistent(CuratorZookeeperClient.java:76)
... 27 more

项目结构为:
dubbo-demo
- dubbo-demo-api
- com.ruyi.dubbo.demo.DemoService.java
- dubbo-demo-provider
- com.ruyi.dubbo.demo.provider.DemoServiceImpl
- com.ruyi.dubbo.demo.provider.Provider
- META-INF/spring/dubbo-demo-provider.xml
- dubbo-demo-consumer
dubbo-demo-api包含一个DemoService接口:
public interface DemoService {
String sayHello(String name);
}
dubbo-demo-provider包含一个类实现DemoService接口的DemoServiceImpl类:
public class DemoServiceImpl implements DemoService {
@Override
public String sayHello(String name) {
// TODO Auto-generated method stub
return "Hello " + name;
}
}
以及一个Provider类:
public class Provider {
public static void main(String[] args) throws Exception {
//Prevent to get IPV6 address,this way only work in debug mode
//But you can pass use -Djava.net.preferIPv4Stack=true,then it work well whether in debug mode or not
System.setProperty("java.net.preferIPv4Stack", "true");
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"META-INF/spring/dubbo-demo-provider.xml"});
context.start();

    System.in.read(); // press any key to exit
}

}
dubbo-demo-provider.xml:
<?xml version="1.0" encoding="UTF-8"?>

xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">

<!-- provider's application name, used for tracing dependency relationship -->
<dubbo:application name="dubbo-demo-provider"/>

<!-- use multicast registry center to export service -->
<!-- <dubbo:registry address="multicast://224.5.6.7:1234"/> -->
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>

<!-- use dubbo protocol to export service on port 20880 -->
<dubbo:protocol name="dubbo" port="20880"/>

<!-- service implementation, as same as regular local bean -->
<bean id="demoService" class="com.ruyi.dubbo.demo.provider.DemoServiceImpl"/>

<!-- declare the service interface to be exported -->
<dubbo:service interface="com.ruyi.dubbo.demo.DemoService" ref="demoService"/>


dubbo-demo-consumer项目(略)

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

4条回答 默认 最新

  • 已采纳
    u011049527 dcasfasf 2018-06-12 16:40

    zk好像有问题,起来了么

    点赞 1 评论 复制链接分享
  • caozhy 从今以后生命中的每一秒都属于我爱的人 2018-06-12 16:05
    点赞 评论 复制链接分享
  • ruyi159 意心一忆 2018-06-12 17:28

    @u011049527 图片说明
    参考如图所示。

    点赞 评论 复制链接分享
  • PGKE915 yikeshuo 2018-06-13 08:25

    服务启动之后恶意关闭导致的的吧 可能就需要重启zk

    点赞 评论 复制链接分享

相关推荐