master
,工程是 dubbo-2.6.5-demo
<dependencies>
<dependency>
<groupId>com.alibabagroupId>
<artifactId>dubboartifactId>
<version>2.6.5version>
dependency>
<dependency>
<groupId>org.apache.zookeepergroupId>
<artifactId>zookeeperartifactId>
<version>3.4.13version>
dependency>
<dependency>
<groupId>org.apache.curatorgroupId>
<artifactId>curator-frameworkartifactId>
<version>2.9.1version>
dependency>
<dependency>
<groupId>org.apache.curatorgroupId>
<artifactId>curator-recipesartifactId>
<version>2.9.1version>
dependency>
dependencies>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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.xsd
http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
<dubbo:application name="demo-provider">
<dubbo:parameter key="qos.enable" value="false"/>
dubbo:application>
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
<dubbo:protocol name="dubbo" port="20880"/>
<dubbo:protocol name="dubbo" port="20881"/>
<dubbo:protocol name="dubbo" port="20882"/>
<dubbo:service interface="pers.masteryourself.study.dubbo.api.DemoService" ref="demoService"/>
<bean id="demoService" class="pers.masteryourself.study.dubbo.provider.DemoServiceImpl"/>
beans>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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.xsd
http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
<dubbo:application name="demo-consumer">
<dubbo:parameter key="qos.enable" value="false"/>
dubbo:application>
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
<dubbo:reference id="demoService" check="false" interface="pers.masteryourself.study.dubbo.api.DemoService" cluster="failfast"/>
beans>
###set log levels###
log4j.rootLogger=info, stdout
###output to the console###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%d{dd/MM/yy HH:mm:ss:SSS z}] %t %5p %c{2}: %m%n
public interface DemoService {
String sayHello(String name);
}
public class DemoServiceImpl implements DemoService {
@Override
public String sayHello(String name) {
URL url = RpcContext.getContext().getUrl();
String message = String.format(" protocol is %s, address is %s", url.getProtocol(), url.getAddress());
// cluster 策略演示
try {
System.out.println("调用此方法了。。。" + message);
TimeUnit.SECONDS.sleep(2);
} catch (InterruptedException e) {
e.printStackTrace();
}
return "你好:" + name + message;
}
}
public class Provider {
public static void main(String[] args) throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:provider.xml");
context.start();
System.in.read();
}
}
public class Consumer {
public static void main(String[] args) throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("consumer.xml");
context.start();
DemoService demoService = context.getBean("demoService", DemoService.class);
while (true){
try {
System.out.println(demoService.sayHello("dubbo"));
} catch (Exception e) {
System.out.println("报错了:" + e.getMessage());
}
TimeUnit.SECONDS.sleep(2);
}
// cluster 策略演示
//System.out.println(demoService.sayHello("dubbo"));
}
}
dubbo-admin-2.6.x
,启动类是 DubboAdminApplication
你好:dubbo protocol is dubbo, address is 192.168.89.1:20881
你好:dubbo protocol is dubbo, address is 192.168.89.1:20880
你好:dubbo protocol is dubbo, address is 192.168.89.1:20882
你好:dubbo protocol is dubbo, address is 192.168.89.1:20882
你好:dubbo protocol is dubbo, address is 192.168.89.1:20881
你好:dubbo protocol is dubbo, address is 192.168.89.1:20881
你好:dubbo protocol is dubbo, address is 192.168.89.1:20882
[08/12/19 11:40:55:518 CST] main-EventThread INFO zookeeper.ZookeeperRegistry: [DUBBO] Notify urls for subscribe url consumer://192.168.89.1/pers.masteryourself.study.dubbo.api.DemoService?application=demo-consumer&category=providers,configurators,routers&check=false&dubbo=2.0.2&interface=pers.masteryourself.study.dubbo.api.DemoService&methods=sayHello&pid=27312&qos.enable=false&side=consumer×tamp=1575776384364, urls: [override://0.0.0.0/pers.masteryourself.study.dubbo.api.DemoService?category=configurators&dynamic=false&enabled=true&sayHello.loadbalance=roundrobin], dubbo version: 2.6.5, current host: 192.168.89.1
你好:dubbo protocol is dubbo, address is 192.168.89.1:20880
你好:dubbo protocol is dubbo, address is 192.168.89.1:20880
你好:dubbo protocol is dubbo, address is 192.168.89.1:20881
你好:dubbo protocol is dubbo, address is 192.168.89.1:20882
你好:dubbo protocol is dubbo, address is 192.168.89.1:20880
你好:dubbo protocol is dubbo, address is 192.168.89.1:20881
你好:dubbo protocol is dubbo, address is 192.168.89.1:20882
你好:dubbo protocol is dubbo, address is 192.168.89.1:20880
你好:dubbo protocol is dubbo, address is 192.168.89.1:20881
你好:dubbo protocol is dubbo, address is 192.168.89.1:20882
你好:dubbo protocol is dubbo, address is 192.168.89.1:20880
你好:dubbo protocol is dubbo, address is 192.168.89.1:20881
[08/12/19 11:45:32:000 CST] main-EventThread INFO zookeeper.ZookeeperRegistry: [DUBBO] Notify urls for subscribe url consumer://192.168.89.1/pers.masteryourself.study.dubbo.api.DemoService?application=demo-consumer&category=providers,configurators,routers&check=false&dubbo=2.0.2&interface=pers.masteryourself.study.dubbo.api.DemoService&methods=sayHello&pid=27312&qos.enable=false&side=consumer×tamp=1575776384364, urls: [override://0.0.0.0/pers.masteryourself.study.dubbo.api.DemoService?category=configurators&dynamic=false&enabled=true&sayHello.loadbalance=roundrobin, override://192.168.89.1:20880/pers.masteryourself.study.dubbo.api.DemoService?category=configurators&disabled=true&dynamic=false&enabled=true], dubbo version: 2.6.5, current host: 192.168.89.1
[08/12/19 11:45:32:001 CST] main-EventThread INFO netty.NettyChannel: [DUBBO] Close netty channel [id: 0x02af004b, /192.168.89.1:61519 => /192.168.89.1:20880], dubbo version: 2.6.5, current host: 192.168.89.1
[08/12/19 11:45:32:003 CST] DubboSharedHandler-thread-1 INFO dubbo.DubboProtocol: [DUBBO] disconnected from /192.168.89.1:20880,url:dubbo://192.168.89.1:20880/pers.masteryourself.study.dubbo.api.DemoService?anyhost=true&application=demo-consumer&bean.name=pers.masteryourself.study.dubbo.api.DemoService&check=false&codec=dubbo&dubbo=2.0.2&generic=false&heartbeat=60000&interface=pers.masteryourself.study.dubbo.api.DemoService&methods=sayHello&pid=27312&qos.enable=false®ister.ip=192.168.89.1&remote.timestamp=1575776289701&side=consumer×tamp=1575776384364, dubbo version: 2.6.5, current host: 192.168.89.1
你好:dubbo protocol is dubbo, address is 192.168.89.1:20882
你好:dubbo protocol is dubbo, address is 192.168.89.1:20881
你好:dubbo protocol is dubbo, address is 192.168.89.1:20882
你好:dubbo protocol is dubbo, address is 192.168.89.1:20881
cluster
默认是 failover
,retries
默认是 2
<dubbo:reference id="demoService" check="false" interface="pers.masteryourself.study.dubbo.api.DemoService" cluster="failover" retries="2"/>
调用此方法了。。。 protocol is dubbo, address is 192.168.89.1:20880
调用此方法了。。。 protocol is dubbo, address is 192.168.89.1:20881
调用此方法了。。。 protocol is dubbo, address is 192.168.89.1:20882
[08/12/19 11:58:50:318 CST] DubboClientHandler-192.168.89.1:20880-thread-1 WARN support.DefaultFuture: [DUBBO] The timeout response finally returned at 2019-12-08 11:58:50.318, response Response [id=0, version=null, status=20, event=false, error=null, result=RpcResult [result=你好:dubbo protocol is dubbo, address is 192.168.89.1:20880, exception=null]], channel: /192.168.89.1:61981 -> /192.168.89.1:20880, dubbo version: 2.6.5, current host: 192.168.89.1
[08/12/19 11:58:51:284 CST] DubboClientHandler-192.168.89.1:20881-thread-1 WARN support.DefaultFuture: [DUBBO] The timeout response finally returned at 2019-12-08 11:58:51.284, response Response [id=1, version=null, status=20, event=false, error=null, result=RpcResult [result=你好:dubbo protocol is dubbo, address is 192.168.89.1:20881, exception=null]], channel: /192.168.89.1:61988 -> /192.168.89.1:20881, dubbo version: 2.6.5, current host: 192.168.89.1
Exception in thread "main" com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method sayHello in the service pers.masteryourself.study.dubbo.api.DemoService. Tried 3 times of the providers [192.168.89.1:20882, 192.168.89.1:20881, 192.168.89.1:20880] (3/3) from the registry 127.0.0.1:2181 on the consumer 192.168.89.1 using the dubbo version 2.6.5. Last error is: Invoke remote method timeout. method: sayHello, provider: dubbo://192.168.89.1:20882/pers.masteryourself.study.dubbo.api.DemoService?anyhost=true&application=demo-consumer&bean.name=pers.masteryourself.study.dubbo.api.DemoService&check=false&dubbo=2.0.2&generic=false&interface=pers.masteryourself.study.dubbo.api.DemoService&methods=sayHello&pid=28056&qos.enable=false®ister.ip=192.168.89.1&remote.timestamp=1575777348168&sayHello.loadbalance=roundrobin&side=consumer×tamp=1575777527245, cause: Waiting server-side response timeout by scan timer. start time: 2019-12-08 11:58:50.284, end time: 2019-12-08 11:58:51.299, client elapsed: 0 ms, server elapsed: 1014 ms, timeout: 1000 ms, request: Request [id=2, version=2.0.2, twoway=true, event=false, broken=false, data=RpcInvocation [methodName=sayHello, parameterTypes=[class java.lang.String], arguments=[dubbo], attachments={path=pers.masteryourself.study.dubbo.api.DemoService, interface=pers.masteryourself.study.dubbo.api.DemoService, version=0.0.0}]], channel: /192.168.89.1:61993 -> /192.168.89.1:20882
at com.alibaba.dubbo.rpc.cluster.support.FailoverClusterInvoker.doInvoke(FailoverClusterInvoker.java:109)
at com.alibaba.dubbo.rpc.cluster.support.AbstractClusterInvoker.invoke(AbstractClusterInvoker.java:244)
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.sayHello(proxy0.java)
at pers.masteryourself.study.dubbo.consumer.Consumer.main(Consumer.java:27)
Caused by: com.alibaba.dubbo.remoting.TimeoutException: Waiting server-side response timeout by scan timer. start time: 2019-12-08 11:58:50.284, end time: 2019-12-08 11:58:51.299, client elapsed: 0 ms, server elapsed: 1014 ms, timeout: 1000 ms, request: Request [id=2, version=2.0.2, twoway=true, event=false, broken=false, data=RpcInvocation [methodName=sayHello, parameterTypes=[class java.lang.String], arguments=[dubbo], attachments={path=pers.masteryourself.study.dubbo.api.DemoService, interface=pers.masteryourself.study.dubbo.api.DemoService, version=0.0.0}]], channel: /192.168.89.1:61993 -> /192.168.89.1:20882
at com.alibaba.dubbo.remoting.exchange.support.DefaultFuture.returnFromResponse(DefaultFuture.java:243)
at com.alibaba.dubbo.remoting.exchange.support.DefaultFuture.get(DefaultFuture.java:162)
at com.alibaba.dubbo.remoting.exchange.support.DefaultFuture.get(DefaultFuture.java:135)
at com.alibaba.dubbo.rpc.protocol.dubbo.DubboInvoker.doInvoke(DubboInvoker.java:95)
at com.alibaba.dubbo.rpc.protocol.AbstractInvoker.invoke(AbstractInvoker.java:155)
at com.alibaba.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:75)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72)
at com.alibaba.dubbo.rpc.protocol.dubbo.filter.FutureFilter.invoke(FutureFilter.java:54)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72)
at com.alibaba.dubbo.rpc.filter.ConsumerContextFilter.invoke(ConsumerContextFilter.java:49)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72)
at com.alibaba.dubbo.rpc.listener.ListenerInvokerWrapper.invoke(ListenerInvokerWrapper.java:77)
at com.alibaba.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:56)
at com.alibaba.dubbo.rpc.cluster.support.FailoverClusterInvoker.doInvoke(FailoverClusterInvoker.java:78)
... 5 more
<dubbo:reference id="demoService" check="false" interface="pers.masteryourself.study.dubbo.api.DemoService" cluster="failfast"/>
容错即调用失败后会返回配置好的值(这里是 null)
容错也可以直接在动态配置里配置
报错了:Failfast invoke providers dubbo://192.168.89.1:20880/pers.masteryourself.study.dubbo.api.DemoService?anyhost=true&application=demo-consumer&bean.name=pers.masteryourself.study.dubbo.api.DemoService&check=false&cluster=failfast&dubbo=2.0.2&generic=false&interface=pers.masteryourself.study.dubbo.api.DemoService&methods=sayHello&pid=27312&qos.enable=false®ister.ip=192.168.89.1&remote.timestamp=1575778266928&sayHello.loadbalance=roundrobin&side=consumer×tamp=1575778324224 RoundRobinLoadBalance select from all providers [com.alibaba.dubbo.registry.integration.RegistryDirectory$InvokerDelegate@37911f88, com.alibaba.dubbo.registry.integration.RegistryDirectory$InvokerDelegate@6f1c29b7, com.alibaba.dubbo.registry.integration.RegistryDirectory$InvokerDelegate@4d6025c5] for service pers.masteryourself.study.dubbo.api.DemoService method sayHello on consumer 192.168.89.1 use dubbo version 2.6.5, but no luck to perform the invocation. Last error is: Invoke remote method timeout. method: sayHello, provider: dubbo://192.168.89.1:20880/pers.masteryourself.study.dubbo.api.DemoService?anyhost=true&application=demo-consumer&bean.name=pers.masteryourself.study.dubbo.api.DemoService&check=false&cluster=failfast&dubbo=2.0.2&generic=false&interface=pers.masteryourself.study.dubbo.api.DemoService&methods=sayHello&pid=27312&qos.enable=false®ister.ip=192.168.89.1&remote.timestamp=1575778266928&sayHello.loadbalance=roundrobin&side=consumer×tamp=1575778324224, cause: Waiting server-side response timeout. start time: 2019-12-08 12:12:20.045, end time: 2019-12-08 12:12:21.046, client elapsed: 0 ms, server elapsed: 1001 ms, timeout: 1000 ms, request: Request [id=5, version=2.0.2, twoway=true, event=false, broken=false, data=RpcInvocation [methodName=sayHello, parameterTypes=[class java.lang.String], arguments=[dubbo], attachments={path=pers.masteryourself.study.dubbo.api.DemoService, interface=pers.masteryourself.study.dubbo.api.DemoService, version=0.0.0}]], channel: /192.168.89.1:62331 -> /192.168.89.1:20880
[08/12/19 12:12:22:046 CST] DubboClientHandler-192.168.89.1:20880-thread-1 WARN support.DefaultFuture: [DUBBO] The timeout response finally returned at 2019-12-08 12:12:22.046, response Response [id=5, version=null, status=20, event=false, error=null, result=RpcResult [result=你好:dubbo protocol is dubbo, address is 192.168.89.1:20880, exception=null]], channel: /192.168.89.1:62331 -> /192.168.89.1:20880, dubbo version: 2.6.5, current host: 192.168.89.1
[08/12/19 12:12:23:358 CST] main-EventThread INFO zookeeper.ZookeeperRegistry: [DUBBO] Notify urls for subscribe url consumer://192.168.89.1/pers.masteryourself.study.dubbo.api.DemoService?application=demo-consumer&category=providers,configurators,routers&check=false&cluster=failfast&dubbo=2.0.2&interface=pers.masteryourself.study.dubbo.api.DemoService&methods=sayHello&pid=27312&qos.enable=false&side=consumer×tamp=1575778324224, urls: [override://192.168.89.1/pers.masteryourself.study.dubbo.api.DemoService?category=configurators&dynamic=false&enabled=true&mock=fail%3Areturn+null, override://0.0.0.0/pers.masteryourself.study.dubbo.api.DemoService?category=configurators&dynamic=false&enabled=true&sayHello.loadbalance=roundrobin], dubbo version: 2.6.5, current host: 192.168.89.1
报错了:Failfast invoke providers dubbo://192.168.89.1:20881/pers.masteryourself.study.dubbo.api.DemoService?anyhost=true&application=demo-consumer&bean.name=pers.masteryourself.study.dubbo.api.DemoService&check=false&cluster=failfast&dubbo=2.0.2&generic=false&interface=pers.masteryourself.study.dubbo.api.DemoService&methods=sayHello&pid=27312&qos.enable=false®ister.ip=192.168.89.1&remote.timestamp=1575778267982&sayHello.loadbalance=roundrobin&side=consumer×tamp=1575778324224 RoundRobinLoadBalance select from all providers [com.alibaba.dubbo.registry.integration.RegistryDirectory$InvokerDelegate@37911f88, com.alibaba.dubbo.registry.integration.RegistryDirectory$InvokerDelegate@6f1c29b7, com.alibaba.dubbo.registry.integration.RegistryDirectory$InvokerDelegate@4d6025c5] for service pers.masteryourself.study.dubbo.api.DemoService method sayHello on consumer 192.168.89.1 use dubbo version 2.6.5, but no luck to perform the invocation. Last error is: Invoke remote method timeout. method: sayHello, provider: dubbo://192.168.89.1:20881/pers.masteryourself.study.dubbo.api.DemoService?anyhost=true&application=demo-consumer&bean.name=pers.masteryourself.study.dubbo.api.DemoService&check=false&cluster=failfast&dubbo=2.0.2&generic=false&interface=pers.masteryourself.study.dubbo.api.DemoService&methods=sayHello&pid=27312&qos.enable=false®ister.ip=192.168.89.1&remote.timestamp=1575778267982&sayHello.loadbalance=roundrobin&side=consumer×tamp=1575778324224, cause: Waiting server-side response timeout by scan timer. start time: 2019-12-08 12:12:23.046, end time: 2019-12-08 12:12:24.047, client elapsed: 0 ms, server elapsed: 1001 ms, timeout: 1000 ms, request: Request [id=6, version=2.0.2, twoway=true, event=false, broken=false, data=RpcInvocation [methodName=sayHello, parameterTypes=[class java.lang.String], arguments=[dubbo], attachments={path=pers.masteryourself.study.dubbo.api.DemoService, interface=pers.masteryourself.study.dubbo.api.DemoService, version=0.0.0}]], channel: /192.168.89.1:62338 -> /192.168.89.1:20881
[08/12/19 12:12:25:048 CST] DubboClientHandler-192.168.89.1:20881-thread-1 WARN support.DefaultFuture: [DUBBO] The timeout response finally returned at 2019-12-08 12:12:25.048, response Response [id=6, version=null, status=20, event=false, error=null, result=RpcResult [result=你好:dubbo protocol is dubbo, address is 192.168.89.1:20881, exception=null]], channel: /192.168.89.1:62338 -> /192.168.89.1:20881, dubbo version: 2.6.5, current host: 192.168.89.1
[08/12/19 12:12:27:073 CST] main WARN wrapper.MockClusterInvoker: [DUBBO] fail-mock: sayHello fail-mock enabled , url : zookeeper://127.0.0.1:2181/com.alibaba.dubbo.registry.RegistryService?anyhost=true&application=demo-consumer&bean.name=pers.masteryourself.study.dubbo.api.DemoService&check=false&cluster=failfast&dubbo=2.0.2&generic=false&interface=pers.masteryourself.study.dubbo.api.DemoService&methods=sayHello&mock=fail%3Areturn+null&pid=27312&qos.enable=false®ister.ip=192.168.89.1&remote.timestamp=1575778268014&sayHello.loadbalance=roundrobin&side=consumer×tamp=1575778324224, dubbo version: 2.6.5, current host: 192.168.89.1
com.alibaba.dubbo.rpc.RpcException: Failfast invoke providers dubbo://192.168.89.1:20880/pers.masteryourself.study.dubbo.api.DemoService?anyhost=true&application=demo-consumer&bean.name=pers.masteryourself.study.dubbo.api.DemoService&check=false&cluster=failfast&dubbo=2.0.2&generic=false&interface=pers.masteryourself.study.dubbo.api.DemoService&methods=sayHello&mock=fail%3Areturn+null&pid=27312&qos.enable=false®ister.ip=192.168.89.1&remote.timestamp=1575778266928&sayHello.loadbalance=roundrobin&side=consumer×tamp=1575778324224 RoundRobinLoadBalance select from all providers [com.alibaba.dubbo.registry.integration.RegistryDirectory$InvokerDelegate@723e88f9, com.alibaba.dubbo.registry.integration.RegistryDirectory$InvokerDelegate@5f0fd5a0, com.alibaba.dubbo.registry.integration.RegistryDirectory$InvokerDelegate@64e7619d] for service pers.masteryourself.study.dubbo.api.DemoService method sayHello on consumer 192.168.89.1 use dubbo version 2.6.5, but no luck to perform the invocation. Last error is: Invoke remote method timeout. method: sayHello, provider: dubbo://192.168.89.1:20880/pers.masteryourself.study.dubbo.api.DemoService?anyhost=true&application=demo-consumer&bean.name=pers.masteryourself.study.dubbo.api.DemoService&check=false&cluster=failfast&dubbo=2.0.2&generic=false&interface=pers.masteryourself.study.dubbo.api.DemoService&methods=sayHello&mock=fail%3Areturn+null&pid=27312&qos.enable=false®ister.ip=192.168.89.1&remote.timestamp=1575778266928&sayHello.loadbalance=roundrobin&side=consumer×tamp=1575778324224, cause: Waiting server-side response timeout by scan timer. start time: 2019-12-08 12:12:26.048, end time: 2019-12-08 12:12:27.073, client elapsed: 0 ms, server elapsed: 1025 ms, timeout: 1000 ms, request: Request [id=7, version=2.0.2, twoway=true, event=false, broken=false, data=RpcInvocation [methodName=sayHello, parameterTypes=[class java.lang.String], arguments=[dubbo], attachments={path=pers.masteryourself.study.dubbo.api.DemoService, interface=pers.masteryourself.study.dubbo.api.DemoService, version=0.0.0}]], channel: /192.168.89.1:62331 -> /192.168.89.1:20880
at com.alibaba.dubbo.rpc.cluster.support.FailfastClusterInvoker.doInvoke(FailfastClusterInvoker.java:53)
at com.alibaba.dubbo.rpc.cluster.support.AbstractClusterInvoker.invoke(AbstractClusterInvoker.java:244)
at com.alibaba.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker.invoke(MockClusterInvoker.java:85)
at com.alibaba.dubbo.rpc.proxy.InvokerInvocationHandler.invoke(InvokerInvocationHandler.java:52)
at com.alibaba.dubbo.common.bytecode.proxy0.sayHello(proxy0.java)
at pers.masteryourself.study.dubbo.consumer.Consumer.main(Consumer.java:24)
Caused by: com.alibaba.dubbo.remoting.TimeoutException: Waiting server-side response timeout by scan timer. start time: 2019-12-08 12:12:26.048, end time: 2019-12-08 12:12:27.073, client elapsed: 0 ms, server elapsed: 1025 ms, timeout: 1000 ms, request: Request [id=7, version=2.0.2, twoway=true, event=false, broken=false, data=RpcInvocation [methodName=sayHello, parameterTypes=[class java.lang.String], arguments=[dubbo], attachments={path=pers.masteryourself.study.dubbo.api.DemoService, interface=pers.masteryourself.study.dubbo.api.DemoService, version=0.0.0}]], channel: /192.168.89.1:62331 -> /192.168.89.1:20880
at com.alibaba.dubbo.remoting.exchange.support.DefaultFuture.returnFromResponse(DefaultFuture.java:243)
at com.alibaba.dubbo.remoting.exchange.support.DefaultFuture.get(DefaultFuture.java:162)
at com.alibaba.dubbo.remoting.exchange.support.DefaultFuture.get(DefaultFuture.java:135)
at com.alibaba.dubbo.rpc.protocol.dubbo.DubboInvoker.doInvoke(DubboInvoker.java:95)
at com.alibaba.dubbo.rpc.protocol.AbstractInvoker.invoke(AbstractInvoker.java:155)
at com.alibaba.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:75)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72)
at com.alibaba.dubbo.rpc.protocol.dubbo.filter.FutureFilter.invoke(FutureFilter.java:54)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72)
at com.alibaba.dubbo.rpc.filter.ConsumerContextFilter.invoke(ConsumerContextFilter.java:49)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72)
at com.alibaba.dubbo.rpc.listener.ListenerInvokerWrapper.invoke(ListenerInvokerWrapper.java:77)
at com.alibaba.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:56)
at com.alibaba.dubbo.rpc.cluster.support.FailfastClusterInvoker.doInvoke(FailfastClusterInvoker.java:48)
... 5 more
null
报错了:Failfast invoke providers dubbo://192.168.89.1:20880/pers.masteryourself.study.dubbo.api.DemoService?anyhost=true&application=demo-consumer&bean.name=pers.masteryourself.study.dubbo.api.DemoService&check=false&cluster=failfast&dubbo=2.0.2&generic=false&interface=pers.masteryourself.study.dubbo.api.DemoService&methods=sayHello&pid=27312&qos.enable=false®ister.ip=192.168.89.1&remote.timestamp=1575778266928&sayHello.loadbalance=roundrobin&side=consumer×tamp=1575778324224 RoundRobinLoadBalance select from all providers [com.alibaba.dubbo.registry.integration.RegistryDirectory$InvokerDelegate@3697186, com.alibaba.dubbo.registry.integration.RegistryDirectory$InvokerDelegate@1583741e, com.alibaba.dubbo.registry.integration.RegistryDirectory$InvokerDelegate@5b367418] for service pers.masteryourself.study.dubbo.api.DemoService method sayHello on consumer 192.168.89.1 use dubbo version 2.6.5, but no luck to perform the invocation. Last error is: Invoke remote method timeout. method: sayHello, provider: dubbo://192.168.89.1:20880/pers.masteryourself.study.dubbo.api.DemoService?anyhost=true&application=demo-consumer&bean.name=pers.masteryourself.study.dubbo.api.DemoService&check=false&cluster=failfast&dubbo=2.0.2&generic=false&interface=pers.masteryourself.study.dubbo.api.DemoService&methods=sayHello&pid=27312&qos.enable=false®ister.ip=192.168.89.1&remote.timestamp=1575778266928&sayHello.loadbalance=roundrobin&side=consumer×tamp=1575778324224, cause: Waiting server-side response timeout. start time: 2019-12-08 12:22:39.469, end time: 2019-12-08 12:22:40.470, client elapsed: 0 ms, server elapsed: 1001 ms, timeout: 1000 ms, request: Request [id=211, version=2.0.2, twoway=true, event=false, broken=false, data=RpcInvocation [methodName=sayHello, parameterTypes=[class java.lang.String], arguments=[dubbo], attachments={path=pers.masteryourself.study.dubbo.api.DemoService, interface=pers.masteryourself.study.dubbo.api.DemoService, version=0.0.0}]], channel: /192.168.89.1:62331 -> /192.168.89.1:20880
[08/12/19 12:22:41:470 CST] DubboClientHandler-192.168.89.1:20880-thread-1 WARN support.DefaultFuture: [DUBBO] The timeout response finally returned at 2019-12-08 12:22:41.470, response Response [id=211, version=null, status=20, event=false, error=null, result=RpcResult [result=你好:dubbo protocol is dubbo, address is 192.168.89.1:20880, exception=null]], channel: /192.168.89.1:62331 -> /192.168.89.1:20880, dubbo version: 2.6.5, current host: 192.168.89.1
报错了:Failfast invoke providers dubbo://192.168.89.1:20881/pers.masteryourself.study.dubbo.api.DemoService?anyhost=true&application=demo-consumer&bean.name=pers.masteryourself.study.dubbo.api.DemoService&check=false&cluster=failfast&dubbo=2.0.2&generic=false&interface=pers.masteryourself.study.dubbo.api.DemoService&methods=sayHello&pid=27312&qos.enable=false®ister.ip=192.168.89.1&remote.timestamp=1575778267982&sayHello.loadbalance=roundrobin&side=consumer×tamp=1575778324224 RoundRobinLoadBalance select from all providers [com.alibaba.dubbo.registry.integration.RegistryDirectory$InvokerDelegate@3697186, com.alibaba.dubbo.registry.integration.RegistryDirectory$InvokerDelegate@1583741e, com.alibaba.dubbo.registry.integration.RegistryDirectory$InvokerDelegate@5b367418] for service pers.masteryourself.study.dubbo.api.DemoService method sayHello on consumer 192.168.89.1 use dubbo version 2.6.5, but no luck to perform the invocation. Last error is: Invoke remote method timeout. method: sayHello, provider: dubbo://192.168.89.1:20881/pers.masteryourself.study.dubbo.api.DemoService?anyhost=true&application=demo-consumer&bean.name=pers.masteryourself.study.dubbo.api.DemoService&check=false&cluster=failfast&dubbo=2.0.2&generic=false&interface=pers.masteryourself.study.dubbo.api.DemoService&methods=sayHello&pid=27312&qos.enable=false®ister.ip=192.168.89.1&remote.timestamp=1575778267982&sayHello.loadbalance=roundrobin&side=consumer×tamp=1575778324224, cause: Waiting server-side response timeout. start time: 2019-12-08 12:22:42.470, end time: 2019-12-08 12:22:43.472, client elapsed: 0 ms, server elapsed: 1002 ms, timeout: 1000 ms, request: Request [id=212, version=2.0.2, twoway=true, event=false, broken=false, data=RpcInvocation [methodName=sayHello, parameterTypes=[class java.lang.String], arguments=[dubbo], attachments={path=pers.masteryourself.study.dubbo.api.DemoService, interface=pers.masteryourself.study.dubbo.api.DemoService, version=0.0.0}]], channel: /192.168.89.1:62338 -> /192.168.89.1:20881
[08/12/19 12:22:43:829 CST] main-EventThread INFO zookeeper.ZookeeperRegistry: [DUBBO] Notify urls for subscribe url consumer://192.168.89.1/pers.masteryourself.study.dubbo.api.DemoService?application=demo-consumer&category=providers,configurators,routers&check=false&cluster=failfast&dubbo=2.0.2&interface=pers.masteryourself.study.dubbo.api.DemoService&methods=sayHello&pid=27312&qos.enable=false&side=consumer×tamp=1575778324224, urls: [override://0.0.0.0/pers.masteryourself.study.dubbo.api.DemoService?category=configurators&dynamic=false&enabled=true&sayHello.loadbalance=roundrobin], dubbo version: 2.6.5, current host: 192.168.89.1
[08/12/19 12:22:43:857 CST] main-EventThread INFO zookeeper.ZookeeperRegistry: [DUBBO] Notify urls for subscribe url consumer://192.168.89.1/pers.masteryourself.study.dubbo.api.DemoService?application=demo-consumer&category=providers,configurators,routers&check=false&cluster=failfast&dubbo=2.0.2&interface=pers.masteryourself.study.dubbo.api.DemoService&methods=sayHello&pid=27312&qos.enable=false&side=consumer×tamp=1575778324224, urls: [override://0.0.0.0/pers.masteryourself.study.dubbo.api.DemoService?category=configurators&dynamic=false&enabled=true&mock=force%3Areturn+%22%E5%BC%BA%E5%88%B6%E8%BF%94%E5%9B%9E%E8%BF%99%E4%B8%AA%E5%80%BC%22, override://0.0.0.0/pers.masteryourself.study.dubbo.api.DemoService?category=configurators&dynamic=false&enabled=true&sayHello.loadbalance=roundrobin], dubbo version: 2.6.5, current host: 192.168.89.1
[08/12/19 12:22:44:471 CST] DubboClientHandler-192.168.89.1:20881-thread-1 WARN support.DefaultFuture: [DUBBO] The timeout response finally returned at 2019-12-08 12:22:44.471, response Response [id=212, version=null, status=20, event=false, error=null, result=RpcResult [result=你好:dubbo protocol is dubbo, address is 192.168.89.1:20881, exception=null]], channel: /192.168.89.1:62338 -> /192.168.89.1:20881, dubbo version: 2.6.5, current host: 192.168.89.1
[08/12/19 12:22:45:472 CST] main INFO wrapper.MockClusterInvoker: [DUBBO] force-mock: sayHello force-mock enabled , url : zookeeper://127.0.0.1:2181/com.alibaba.dubbo.registry.RegistryService?anyhost=true&application=demo-consumer&bean.name=pers.masteryourself.study.dubbo.api.DemoService&check=false&cluster=failfast&dubbo=2.0.2&generic=false&interface=pers.masteryourself.study.dubbo.api.DemoService&methods=sayHello&mock=force%3Areturn+%22%E5%BC%BA%E5%88%B6%E8%BF%94%E5%9B%9E%E8%BF%99%E4%B8%AA%E5%80%BC%22&pid=27312&qos.enable=false®ister.ip=192.168.89.1&remote.timestamp=1575778268014&sayHello.loadbalance=roundrobin&side=consumer×tamp=1575778324224, dubbo version: 2.6.5, current host: 192.168.89.1
强制返回这个值
[08/12/19 12:22:47:474 CST] main INFO wrapper.MockClusterInvoker: [DUBBO] force-mock: sayHello force-mock enabled , url : zookeeper://127.0.0.1:2181/com.alibaba.dubbo.registry.RegistryService?anyhost=true&application=demo-consumer&bean.name=pers.masteryourself.study.dubbo.api.DemoService&check=false&cluster=failfast&dubbo=2.0.2&generic=false&interface=pers.masteryourself.study.dubbo.api.DemoService&methods=sayHello&mock=force%3Areturn+%22%E5%BC%BA%E5%88%B6%E8%BF%94%E5%9B%9E%E8%BF%99%E4%B8%AA%E5%80%BC%22&pid=27312&qos.enable=false®ister.ip=192.168.89.1&remote.timestamp=1575778268014&sayHello.loadbalance=roundrobin&side=consumer×tamp=1575778324224, dubbo version: 2.6.5, current host: 192.168.89.1
强制返回这个值
权重调节和负载均衡的功能属于动态配置
由于服务提供者 sleep 了 2 秒,导致消费者一直超时,这里用动态配置添加 demo-consumer 的超时时间
报错了:Failfast invoke providers dubbo://192.168.89.1:20880/pers.masteryourself.study.dubbo.api.DemoService?anyhost=true&application=demo-consumer&bean.name=pers.masteryourself.study.dubbo.api.DemoService&check=false&cluster=failfast&dubbo=2.0.2&generic=false&interface=pers.masteryourself.study.dubbo.api.DemoService&methods=sayHello&pid=27312&qos.enable=false®ister.ip=192.168.89.1&remote.timestamp=1575778266928&sayHello.loadbalance=roundrobin&side=consumer×tamp=1575778324224 RoundRobinLoadBalance select from all providers [com.alibaba.dubbo.registry.integration.RegistryDirectory$InvokerDelegate@65b104b9, com.alibaba.dubbo.registry.integration.RegistryDirectory$InvokerDelegate@6c4980d3, com.alibaba.dubbo.registry.integration.RegistryDirectory$InvokerDelegate@327bcebd] for service pers.masteryourself.study.dubbo.api.DemoService method sayHello on consumer 192.168.89.1 use dubbo version 2.6.5, but no luck to perform the invocation. Last error is: Invoke remote method timeout. method: sayHello, provider: dubbo://192.168.89.1:20880/pers.masteryourself.study.dubbo.api.DemoService?anyhost=true&application=demo-consumer&bean.name=pers.masteryourself.study.dubbo.api.DemoService&check=false&cluster=failfast&dubbo=2.0.2&generic=false&interface=pers.masteryourself.study.dubbo.api.DemoService&methods=sayHello&pid=27312&qos.enable=false®ister.ip=192.168.89.1&remote.timestamp=1575778266928&sayHello.loadbalance=roundrobin&side=consumer×tamp=1575778324224, cause: Waiting server-side response timeout by scan timer. start time: 2019-12-08 12:31:19.169, end time: 2019-12-08 12:31:20.182, client elapsed: 1 ms, server elapsed: 1012 ms, timeout: 1000 ms, request: Request [id=295, version=2.0.2, twoway=true, event=false, broken=false, data=RpcInvocation [methodName=sayHello, parameterTypes=[class java.lang.String], arguments=[dubbo], attachments={path=pers.masteryourself.study.dubbo.api.DemoService, interface=pers.masteryourself.study.dubbo.api.DemoService, version=0.0.0}]], channel: /192.168.89.1:62331 -> /192.168.89.1:20880
[08/12/19 12:31:21:170 CST] DubboClientHandler-192.168.89.1:20880-thread-2 WARN support.DefaultFuture: [DUBBO] The timeout response finally returned at 2019-12-08 12:31:21.170, response Response [id=295, version=null, status=20, event=false, error=null, result=RpcResult [result=你好:dubbo protocol is dubbo, address is 192.168.89.1:20880, exception=null]], channel: /192.168.89.1:62331 -> /192.168.89.1:20880, dubbo version: 2.6.5, current host: 192.168.89.1
[08/12/19 12:31:21:939 CST] main-EventThread INFO zookeeper.ZookeeperRegistry: [DUBBO] Notify urls for subscribe url consumer://192.168.89.1/pers.masteryourself.study.dubbo.api.DemoService?application=demo-consumer&category=providers,configurators,routers&check=false&cluster=failfast&dubbo=2.0.2&interface=pers.masteryourself.study.dubbo.api.DemoService&methods=sayHello&pid=27312&qos.enable=false&side=consumer×tamp=1575778324224, urls: [override://0.0.0.0/pers.masteryourself.study.dubbo.api.DemoService?category=configurators&dynamic=false&enabled=true&sayHello.loadbalance=roundrobin], dubbo version: 2.6.5, current host: 192.168.89.1
[08/12/19 12:31:21:977 CST] main-EventThread INFO zookeeper.ZookeeperRegistry: [DUBBO] Notify urls for subscribe url consumer://192.168.89.1/pers.masteryourself.study.dubbo.api.DemoService?application=demo-consumer&category=providers,configurators,routers&check=false&cluster=failfast&dubbo=2.0.2&interface=pers.masteryourself.study.dubbo.api.DemoService&methods=sayHello&pid=27312&qos.enable=false&side=consumer×tamp=1575778324224, urls: [override://192.168.89.1/pers.masteryourself.study.dubbo.api.DemoService?application=demo-consumer&category=configurators&dynamic=false&enabled=true&sayHello.timeout=2500, override://0.0.0.0/pers.masteryourself.study.dubbo.api.DemoService?category=configurators&dynamic=false&enabled=true&sayHello.loadbalance=roundrobin], dubbo version: 2.6.5, current host: 192.168.89.1
你好:dubbo protocol is dubbo, address is 192.168.89.1:20881
你好:dubbo protocol is dubbo, address is 192.168.89.1:20882
你好:dubbo protocol is dubbo, address is 192.168.89.1:20880
访问控制的功能属于路由规则
给 demo-consumer 应用添加一条路由规则,让它只能消费到 20880 端口提供出来的服务
你好:dubbo protocol is dubbo, address is 192.168.89.1:20881
你好:dubbo protocol is dubbo, address is 192.168.89.1:20882
[08/12/19 12:34:43:837 CST] main-EventThread INFO zookeeper.ZookeeperRegistry: [DUBBO] Notify urls for subscribe url consumer://192.168.89.1/pers.masteryourself.study.dubbo.api.DemoService?application=demo-consumer&category=providers,configurators,routers&check=false&cluster=failfast&dubbo=2.0.2&interface=pers.masteryourself.study.dubbo.api.DemoService&methods=sayHello&pid=27312&qos.enable=false&side=consumer×tamp=1575778324224, urls: [empty://192.168.89.1/pers.masteryourself.study.dubbo.api.DemoService?application=demo-consumer&category=routers&check=false&cluster=failfast&dubbo=2.0.2&interface=pers.masteryourself.study.dubbo.api.DemoService&methods=sayHello&pid=27312&qos.enable=false&side=consumer×tamp=1575778324224], dubbo version: 2.6.5, current host: 192.168.89.1
[08/12/19 12:34:43:877 CST] main-EventThread INFO zookeeper.ZookeeperRegistry: [DUBBO] Notify urls for subscribe url consumer://192.168.89.1/pers.masteryourself.study.dubbo.api.DemoService?application=demo-consumer&category=providers,configurators,routers&check=false&cluster=failfast&dubbo=2.0.2&interface=pers.masteryourself.study.dubbo.api.DemoService&methods=sayHello&pid=27312&qos.enable=false&side=consumer×tamp=1575778324224, urls: [route://0.0.0.0/pers.masteryourself.study.dubbo.api.DemoService?category=routers&dynamic=false&enabled=true&force=false&name=test1&priority=0&router=condition&rule=consumer.application+%3D+demo-consumer+%3D%3E+provider.port+%3D+20880&runtime=false], dubbo version: 2.6.5, current host: 192.168.89.1
你好:dubbo protocol is dubbo, address is 192.168.89.1:20880
你好:dubbo protocol is dubbo, address is 192.168.89.1:20880