Main方法中触发dubbo调用

来源:互联网 发布:网络互动平台骗局 编辑:程序博客网 时间:2024/05/17 04:44

当你写好一个DUBBO接口 如果通过自己产生测试数据进行测试的时候 可以使用Main方法触发你的接口调用 方式如下:


public class Test {

static ApplicationConfig ac = null;
static RegistryConfig rc = null;

static{
try{
ac = new ApplicationConfig();
ac.setName("Test");//应用名字
rc  = new RegistryConfig();
rc.setAddress("zookeeper://10.58.57.58:2181?backup=10.58.57.54:2181,10.58.57.48:2181");//zookeeper注册中心地址
rc.setProtocol("zookeeper");//协议
}catch(Exception e){
e.printStackTrace();
}
}

private static <T> T getProvider(Class<T> c,String group){
ReferenceConfig<T> rcc = new ReferenceConfig<T>();
rcc.setTimeout(50000);
rcc.setRegistry(rc);
rcc.setApplication(ac);
rcc.setCheck(false);
rcc.setInterface(c);
rcc.setGroup(group);
return  rcc.get();
}


public static void test(){
//1准备接口参数

                EsOrder e = new EsOrder();
e.setSUB_ORDER_ID("123");
//2根据接口的字节码和服务的group获得接口引用(此处是dubbo通过你传入的参数 使用动态代理 返回给你接口的引用)
ESearchOperational esop = getProvider(ESearchOperational.class, "pop_order_esop_interface");
esop.insertEsearch(e);
System.out.println("success");
}


public static void main(String[] args) {
test();//执行测试
}
}

0 0
原创粉丝点击