zoukankan      html  css  js  c++  java
  • EchoService

    dubbo为consumer端的代理对象实现了EchoService接口。

    使用示例:

    <dubbo:reference id="hello" interface="com.zhang.HelloService" check="false" />
    EchoService echoService = (EchoService) appCtx.getBean("hello");
    Object str = echoService.$echo("zhang");

    原理:

    public interface EchoService {
        Object $echo(Object message);
    }
    //AbstractProxyFactory
    public <T> T getProxy(Invoker<T> invoker) throws RpcException {
        Class<?>[] interfaces = null;
        String config = invoker.getUrl().getParameter("interfaces");
        if (config != null && config.length() > 0) {
            String[] types = Constants.COMMA_SPLIT_PATTERN.split(config);
            if (types != null && types.length > 0) {
                interfaces = new Class<?>[types.length + 2];
                interfaces[0] = invoker.getInterface();
                interfaces[1] = EchoService.class;
                for (int i = 0; i < types.length; i ++) {
                    interfaces[i + 1] = ReflectUtils.forName(types[i]);
                }
            }
        }
        if (interfaces == null) {
            //加入了EchoService接口
            interfaces = new Class<?>[] {invoker.getInterface(), EchoService.class};
        }
        //JavassistProxyFactory和JdkProxyFactory分别实现EchoService接口
        return getProxy(invoker, interfaces);
    }

    provider在EchoFilter中处理$echo请求:

    @Activate(group = Constants.PROVIDER, order = -110000)
    public class EchoFilter implements Filter {
        public Result invoke(Invoker<?> invoker, Invocation inv) throws RpcException {
            if(inv.getMethodName().equals(Constants.$ECHO) 
            && inv.getArguments() != null && inv.getArguments().length == 1) return new RpcResult(inv.getArguments()[0]); return invoker.invoke(inv); } }
  • 相关阅读:
    MongoDB
    uni-app同步缓存值 设置 读取 删除
    uni-app路由跳转
    uni-app在小程序上遇见的坑(a-b页面频繁跳转)
    unia-app页面生命周期详解
    uni-app之页面跳转(点击按钮进行页面跳转)
    02如何直接使用uni-app中提供的模板之公告滚动
    01-组件轮播
    uni-app如何只用插件市场中的插件
    uni-app在线引入阿里字体图标库
  • 原文地址:https://www.cnblogs.com/allenwas3/p/8400075.html
Copyright © 2011-2022 走看看