dubbo java publish and subscribe (non-spring configuration)

 

dubbo java publish and subscribe (non-spring configuration)

 

 

publish service

  ApplicationConfig config=new ApplicationConfig("springboot-dubbo-productor");
        
        RegistryConfig reg=new RegistryConfig("localhost:2181");
        reg.setProtocol("zookeeper");
        
        ProtocolConfig protocol = new ProtocolConfig();
        protocol.setName("dubbo");
        protocol.setPort(20880);
        
        ServiceConfig<CoreService> service=new ServiceConfig<CoreService>();
        service.setApplication(config);
        service.setRegistry(reg);
        service.setProtocol(protocol);
        service.setInterface(CoreService.class);
        service.setRef(coreService);
        service.setVersion("1.0");
        service.export();

 

 

Subscribe to service

ApplicationConfig config = new ApplicationConfig("springboot-dubbo-consumer");

RegistryConfig reg = new RegistryConfig("localhost:2181");
reg.setProtocol("zookeeper");
				 
ReferenceConfig<CoreService> refrence=new ReferenceConfig<CoreService>();
refrence.setApplication(config);
refrence.setRegistry(reg);
refrence.setInterface(CoreService.class);
refrence.setVersion("1.0");
CoreService  coreService =   refrence.get();

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Donate to developers 

Driven by interest, I write 免费something with joy and sweat. I hope you like my work and can support it at the same time. Of course, if you have money to support a money field (support Alipay, WeChat, and the buckle group), if you have no money to support a personal field, thank you.

 

Personal homepage : http://knight-black-bob.iteye.com/



 
 
 Thank you for your sponsorship, I will do better!

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326078215&siteId=291194637