简体   繁体   English

在春季启动时使用Dubbo遇到“注册时没有提供商”

[英]Using Dubbo in spring boot encountered “no provider available from registration”

This problem arises when consumers want to get the zookeeper value of the local Linux virtual machine 当消费者想要获得本地Linux虚拟机的zookeeper值时,会出现此问题

I used Springboot 2.1,Zookeeper is on the local Linux virtual machine. 我使用的是Springboot 2.1,Zookeeper是在本地的Linux虚拟机上。 I've seen a very close answer, but I don't know how to set it up. 我已经看到了一个非常接近的答案,但我不知道如何设置它。 The address is https://blog.csdn.net/chenxiaochan/article/details/78776304 . 地址是https://blog.csdn.net/chenxiaochan/article/details/78776304 What he means is that the IP of the server published by the Dubbo service uses DHCP, not static. 他的意思是Dubbo服务发布的服务器的IP使用DHCP,而不是静态。 And through his method, I queried my own ip, which is really different from the IP registered in the registry. 通过他的方法,我查询了自己的ip,这与注册表中注册的IP完全不同。 I've also tried to disable virtual network cards, but It means I can't connect to the local Linux virtual machine. 我也尝试禁用虚拟网卡,但这意味着我无法连接到本地Linux虚拟机。

My provider application.properties 我的提供者application.properties

dubbo.application.name=provider-ticket
dubbo.registry.address=zookeeper://192.168.248.132:2181
dubbo.scan.base-packages=com.cq.providerticket.service

My consumer application.properties 我的消费者application.properties

dubbo.application.name=consumer-user
dubbo.registry.address=zookeeper://192.168.248.132:2181
dubbo.consumer.check=false
dubbo.registry.check=false
server.port=8081
dubbo.protocol.host=192.168.248.132
dubbo.provider.host=192.168.248.132

linux dokcer command linux dokcer命令

docker run --name zk01 -p 2181:2181 -p 20880:20880 --restart always -d zookeeperID

This is the Exception it reported. 这是它报告的例外情况。

Caused by: com.alibaba.dubbo.rpc.RpcException: No provider available from registry 192.168.248.132:2181 for service com.cq.consumeruser.ticket.service.TicketService on consumer 10.12.78.96 use dubbo version 2.6.5, please check status of providers(disabled, not registered or in blacklist).
    at com.alibaba.dubbo.registry.integration.RegistryDirectory.doList(RegistryDirectory.java:577)
    at com.alibaba.dubbo.rpc.cluster.directory.AbstractDirectory.list(AbstractDirectory.java:74)
    at com.alibaba.dubbo.rpc.cluster.support.AbstractClusterInvoker.list(AbstractClusterInvoker.java:277)
    at com.alibaba.dubbo.rpc.cluster.support.AbstractClusterInvoker.invoke(AbstractClusterInvoker.java:238)
    at com.alibaba.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker.invoke(MockClusterInvoker.java:75)
    at com.alibaba.dubbo.rpc.proxy.InvokerInvocationHandler.invoke(InvokerInvocationHandler.java:52)
    at com.alibaba.dubbo.common.bytecode.proxy0.getTicket(proxy0.java)
    ... 38 more
java.lang.reflect.UndeclaredThrowableException
    at com.sun.proxy.$Proxy61.getTicket(Unknown Source)
    at com.cq.consumeruser.service.UserService.buyTicket(UserService.java:17)
    at com.cq.consumeruser.ConsumerUserApplicationTests.contextLoads(ConsumerUserApplicationTests.java:21)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)
    at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor$ReferenceBeanInvocationHandler.invoke(ReferenceAnnotationBeanPostProcessor.java:159)
    ... 33 more

If you use docker in linux virtual machine, linux system is run in virutal box or VMware Workstation 如果您在linux虚拟机中使用docker,则linux系统将在虚拟机或VMware Workstation中运行

  1. ssh to linux ssh到linux
  2. vim /etc/sysconfig/network-scripts/ifcfg-eth0 or ifcfg-eth33 file vim / etc / sysconfig / network-scripts / ifcfg-eth0或ifcfg-eth33文件
  3. change the BOOTPROTO=dhcp to BOOTPROTO=static and set IPADDR=192.168.248.132 将BOOTPROTO = dhcp更改为BOOTPROTO = static并设置IPADDR = 192.168.248.132
  4. make sure 20880 and 2181 port is open through firewall 确保通过防火墙打开20880和2181端口

If you use docker for windows,linux virtual is in hyper-v, 192.168.248.132 is your windows computer ip 如果你使用docker for windows,linux virtual是hyper-v,192.168.248.132是你的windows计算机ip

  1. set the dubbo.registry.address=zookeeper://localhost:2181 设置dubbo.registry.address = zookeeper:// localhost:2181
  2. set the dubbo.protocol.host=localhost and dubbo.provider.host=localhost 设置dubbo.protocol.host = localhost和dubbo.provider.host = localhost

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM