dubbo消费端独立启动不依赖spring
所属分类 dubbo
浏览量 990
独立启动不依赖spring
依赖注册中心 或 直接连接
方便 debug ,跟踪源码 理解原理
ClientMain
ApplicationConfig application = new ApplicationConfig();
application.setName("dubbo-client-main");
RegistryConfig registryConfig = new RegistryConfig();
registryConfig.setProtocol("zookeeper");
registryConfig.setAddress("127.0.0.1:2181");
registryConfig.setClient("zkclient");
ReferenceConfig referenceConfig = new ReferenceConfig<>();
referenceConfig.setApplication(application);
referenceConfig.setRegistry(registryConfig);
// random roundrobin leastactive
referenceConfig.setLoadbalance(RandomLoadBalance.NAME);
referenceConfig.setInterface(HelloService.class);
referenceConfig.setVersion("1.0.0");
referenceConfig.setGroup("group1");
HelloService helloService = referenceConfig.get();
String result = helloService.hello("dyyx");
System.out.println(result);
ClientMain2
直接连接 不依赖注册中心
ApplicationConfig application = new ApplicationConfig();
application.setName("dubbo-client-main");
ReferenceConfig referenceConfig = new ReferenceConfig<>();
referenceConfig.setApplication(application);
referenceConfig.setInterface(HelloService.class);
referenceConfig.setUrl("dubbo://127.0.0.1:20880");
referenceConfig.setVersion("1.0.0");
referenceConfig.setGroup("group1");
HelloService helloService = referenceConfig.get();
String result = helloService.hello("dyyx");
System.out.println(result);
完整代码
https://gitee.com/dyyx/dubbodemo/blob/master/dubbo-hello-consumer/src/main/java/dyyx/ClientMain.java
https://gitee.com/dyyx/dubbodemo/blob/master/dubbo-hello-consumer/src/main/java/dyyx/ClientMain2.java
上一篇
下一篇
groovy实例
模板引擎velocity实例
freemarker实例
项目经理要做的事情
Dubbo中的netty使用
中年男人的西游记