zoukankan      html  css  js  c++  java
  • dubbo直连代码示例

            我们都知道dubbo是个分布式的RPC工具,等以后有时间能力允许的话,会好好写下dubbo,当在测试环境我们联调或想指定机器执行之时,是不需要ZK这类调度工具的,当然dubbo也提供了配置的解决方案,很简单,指定URL,但是这里记录的不是这样,是通过代码的方式来直连调用的,就此记录在此。话不多说,上代码

    ApplicationConfig applicationConfig = new ApplicationConfig();
            applicationConfig.setName("mix");
            ReferenceConfig<TaskExecutor> referenceConfig = new ReferenceConfig<TaskExecutor>();
            referenceConfig.setInterface("com.*.TaskExecutor");
            referenceConfig.setUrl("dubbo://127.0.0.1:20880/com.*.TaskExecutor
    
    ");
            referenceConfig.setApplication(applicationConfig);
            MethodConfig methodConfig = new MethodConfig();
            methodConfig.setName("executeTask");
            methodConfig.setAsync(false);
            referenceConfig.setMethods(Arrays.asList(new MethodConfig[]{methodConfig}));
            System.out.println(referenceConfig.get().executeTask(bean));
        }

    其中 com.*.TaskExecutor为接口全名,"dubbo://127.0.0.1:20880/com.*.TaskExecutor"为服务的具体地址,"executeTask"为方法名称,bean为方法参数。

  • 相关阅读:
    【经典数据结构】B树与B+树
    【经典算法】线性时间排序
    【经典算法】归并排序
    【经典算法】快速排序
    python模块之shelve
    python模块之pickle
    python模块之json
    python之序列化
    python模块之shutil和zipfile
    python模块之sys
  • 原文地址:https://www.cnblogs.com/daily-note/p/8416250.html
Copyright © 2011-2022 走看看