06、消费端

    @DubboReference
    private DemoService demoService;

    @Override
    public String sayHello(String name) {
        return demoService.sayHello(name);
    }

上面获取@DubboReference 实际获取的是 InvokerInvocationHandler 代理对象

在这里插入图片描述

@Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if (method.getDeclaringClass() == Object.class) {
            return method.invoke(invoker, args);
        }
        String methodName = method.getName();
        Class<?>[] parameterTypes = method.getParameterTypes();
        if (parameterTypes.length == 0) {
            if ("toString".equals(methodName)) {
                return invoker.toString();
            } else if ("$destroy".equals(methodName)) {
                invoker.destroy();
                return null;
            } else if ("hashCode".equals(methodName)) {
                return invoker.hashCode();
            }
        } else if (parameterTypes.length == 1 && "equals".equals(methodName)) {
            return invoker.equals(args[0]);
        }
        RpcInvocation rpcInvocation = new RpcInvocation(method, invoker.getInterface().getName(), args);
        //org.apache.dubbo.demo.DemoService
        String serviceKey = invoker.getUrl().getServiceKey();
        rpcInvocation.setTargetServiceUniqueName(serviceKey);
      
        if (consumerModel != null) {
            rpcInvocation.put(Constants.CONSUMER_MODEL, consumerModel);
            rpcInvocation.put(Constants.METHOD_MODEL, consumerModel.getMethodModel(method));
        }

        return invoker.invoke(rpcInvocation).recreate();
    }

???????
FailoverClusterInvoker

@Override
    @SuppressWarnings({"unchecked", "rawtypes"})
    public Result doInvoke(Invocation invocation, final List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException {
    /**
    * providerUrl = {URL@4249} "dubbo://192.168.1.188:20880/org.apache.dubbo.demo.DemoService?anyhost=true&application=dubbo-demo-annotation-provider&category=providers&deprecated=false&dubbo=2.0.2&dynamic=true&generic=false&interface=org.apache.dubbo.demo.DemoService&methods=sayHello,sayHelloAsync&path=org.apache.dubbo.demo.DemoService&pid=18280&protocol=dubbo&release=&side=provider&timestamp=1594371345465"
	* invoker = {ProtocolFilterWrapper$1@3832} "interface org.apache.dubbo.demo.DemoService -> dubbo://192.168.1.188:20880/org.apache.dubbo.demo.DemoService?anyhost=true&application=dubbo-demo-annotation-consumer&category=providers&check=false&deprecated=false&dubbo=2.0.2&dynamic=true&generic=false&init=false&interface=org.apache.dubbo.demo.DemoService&methods=sayHello,sayHelloAsync&path=org.apache.dubbo.demo.DemoService&pid=18998&protocol=dubbo&register.ip=192.168.1.188&release=&remote.application=dubbo-demo-annotation-provider&side=consumer&sticky=false&timestamp=1594371345465"
url = {URL@3900} 
	*"dubbo://192.168.1.188:20880/org.apache.dubbo.demo.DemoService?anyhost=true&application=dubbo-demo-annotation-consumer&category=providers&check=false&deprecated=false&dubbo=2.0.2&dynamic=true&generic=false&init=false&interface=org.apache.dubbo.demo.DemoService&methods=sayHello,sayHelloAsync&path=org.apache.dubbo.demo.DemoService&pid=18998&protocol=dubbo&register.ip=192.168.1.188&release=&remote.application=dubbo-demo-annotation-provider&side=consumer&sticky=false&timestamp=1594371345465"
**/
        List<Invoker<T>> copyInvokers = invokers;
        checkInvokers(copyInvokers, invocation);
        String methodName = RpcUtils.getMethodName(invocation);
        int len = getUrl().getMethodParameter(methodName, RETRIES_KEY, DEFAULT_RETRIES) + 1;
        if (len <= 0) {
            len = 1;
        }
        // retry loop.
        RpcException le = null; // last exception.
        List<Invoker<T>> invoked = new ArrayList<Invoker<T>>(copyInvokers.size()); // invoked invokers.
        Set<String> providers = new HashSet<String>(len);
        for (int i = 0; i < len; i++) {
            //Reselect before retry to avoid a change of candidate `invokers`.
            //NOTE: if `invokers` changed, then `invoked` also lose accuracy.
            if (i > 0) {
                checkWhetherDestroyed();
                copyInvokers = list(invocation);
                // check again
                checkInvokers(copyInvokers, invocation);
            }
            Invoker<T> invoker = select(loadbalance, invocation, copyInvokers, invoked);
            invoked.add(invoker);
            RpcContext.getContext().setInvokers((List) invoked);
            try {
                Result result = invoker.invoke(invocation);
                if (le != null && logger.isWarnEnabled()) {
                    logger.warn("Although retry the method " + methodName
                            + " in the service " + getInterface().getName()
                            + " was successful by the provider " + invoker.getUrl().getAddress()
                            + ", but there have been failed providers " + providers
                            + " (" + providers.size() + "/" + copyInvokers.size()
                            + ") from the registry " + directory.getUrl().getAddress()
                            + " on the consumer " + NetUtils.getLocalHost()
                            + " using the dubbo version " + Version.getVersion() + ". Last error is: "
                            + le.getMessage(), le);
                }
                return result;
            } catch (RpcException e) {
                if (e.isBiz()) { // biz exception.
                    throw e;
                }
                le = e;
            } catch (Throwable e) {
                le = new RpcException(e.getMessage(), e);
            } finally {
                providers.add(invoker.getUrl().getAddress());
            }
        }
        throw new RpcException(le.getCode(), "Failed to invoke the method "
                + methodName + " in the service " + getInterface().getName()
                + ". Tried " + len + " times of the providers " + providers
                + " (" + providers.size() + "/" + copyInvokers.size()
                + ") from the registry " + directory.getUrl().getAddress()
                + " on the consumer " + NetUtils.getLocalHost() + " using the dubbo version "
                + Version.getVersion() + ". Last error is: "
                + le.getMessage(), le.getCause() != null ? le.getCause() : le);
    }

InvokerWrapper

@Override
    public Result invoke(Invocation invocation) throws RpcException {
        return invoker.invoke(invocation);
    }

在这里插入图片描述
ProtocolFilterWrapper

FailoverClusterInvoker

DubboInvoker

ProtocolFilterWrapper

[10/07/20 18:56:27:006 CST] main ERROR proxy.InvokerInvocationHandler:  [DUBBO]  invoker.invoke(rpcInvocation) ===>: class org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker  =====>: RpcInvocation [methodName=sayHello, parameterTypes=[class java.lang.String], arguments=[world], attachments={}], dubbo version: , current host: 192.168.1.188
[10/07/20 18:56:27:010 CST] main ERROR wrapper.MockClusterInvoker:  [DUBBO]  invoker.invoke(invocation) ===>: class org.apache.dubbo.rpc.cluster.support.wrapper.AbstractCluster$InterceptorInvokerNode  =====>: RpcInvocation [methodName=sayHello, parameterTypes=[class java.lang.String], arguments=[world], attachments={}], dubbo version: , current host: 192.168.1.188
[10/07/20 18:56:27:028 CST] main ERROR support.FailoverClusterInvoker:  [DUBBO]  invoker.invoke(invocation) ===>: class org.apache.dubbo.registry.integration.RegistryDirectory$InvokerDelegate  =====>: RpcInvocation [methodName=sayHello, parameterTypes=[class java.lang.String], arguments=[world], attachments={}], dubbo version: , current host: 192.168.1.188
[10/07/20 18:56:27:028 CST] main ERROR protocol.InvokerWrapper:  [DUBBO]  invoker.invoke(invocation) ===>: class org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1  =====>: RpcInvocation [methodName=sayHello, parameterTypes=[class java.lang.String], arguments=[world], attachments={}], dubbo version: , current host: 192.168.1.188
[10/07/20 18:56:27:028 CST] main ERROR protocol.ProtocolFilterWrapper:  [DUBBO]  invoker.invoke(invocation) ===>: class org.apache.dubbo.rpc.listener.ListenerInvokerWrapper  =====>: RpcInvocation [methodName=sayHello, parameterTypes=[class java.lang.String], arguments=[world], attachments={}], dubbo version: , current host: 192.168.1.188
[10/07/20 18:56:30:163 CST] main ERROR filter.ConsumerContextFilter:  [DUBBO]  invoker.invoke(invocation) ===>: class org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1  =====>: RpcInvocation [methodName=sayHello, parameterTypes=[class java.lang.String], arguments=[world], attachments={}], dubbo version: , current host: 192.168.1.188
[10/07/20 18:56:30:163 CST] main ERROR protocol.ProtocolFilterWrapper:  [DUBBO]  invoker.invoke(invocation) ===>: class org.apache.dubbo.rpc.listener.ListenerInvokerWrapper  =====>: RpcInvocation [methodName=sayHello, parameterTypes=[class java.lang.String], arguments=[world], attachments={}], dubbo version: , current host: 192.168.1.188
[10/07/20 18:56:30:163 CST] main ERROR filter.FutureFilter:  [DUBBO]  invoker.invoke(invocation) ===>: class org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1  =====>: RpcInvocation [methodName=sayHello, parameterTypes=[class java.lang.String], arguments=[world], attachments={}], dubbo version: , current host: 192.168.1.188
[10/07/20 18:56:30:164 CST] main ERROR protocol.ProtocolFilterWrapper:  [DUBBO]  invoker.invoke(invocation) ===>: class org.apache.dubbo.rpc.listener.ListenerInvokerWrapper  =====>: RpcInvocation [methodName=sayHello, parameterTypes=[class java.lang.String], arguments=[world], attachments={}], dubbo version: , current host: 192.168.1.188
result :Hello world, response from provider: 192.168.1.188:20880``

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值