dubbo源码 学习笔记(四)
2017-10-26 10:49
330 查看
dubbo 通讯协议之injvm
生产者使用两个注册中心 redis 和 zookeeper的
分别对外提供两种协议的接口 dubbo 和 injvm
当我们使用另一个进程启动的时候 这里会抛出异常
因为两个进程不是同一个虚拟机 所以不能使用injvm协议
我们通过修改代码 在生产者中启动一个线程 去运行消费者 这样两个就会在同一个虚拟机中
此时 运行正常
在dubbo源码中有这么个注释 ,发现结果并不是这样的,在去不到jvm的情况下不会去使用别的协议
关于injvm的get set方法已经被淘汰 推荐使用 socpe
但是这里是这样注释的
public class Provider1 { public static void main(String[] args) throws IOException { ApplicationConfig app = new ApplicationConfig("provider"); List<RegistryConfig> registries = new ArrayList<RegistryConfig>(10); registries.add(new RegistryConfig("redis://127.0.0.1:6379")); registries.add(new RegistryConfig("zookeeper://127.0.0.1:2181")); List<ProtocolConfig> protocols = new ArrayList<ProtocolConfig>(10); protocols.add(new ProtocolConfig("dubbo", 20880)); protocols.add(new ProtocolConfig("injvm", 20000)); ServiceConfig<Object> service = new ServiceConfig<Object>(); service.setInterface(HelloService.class); service.setRef(new HelloServiceImpl()); service.setProtocols(protocols); service.setRegistries(registries); service.setApplication(app); service.export(); System.out.println("success"); System.in.read(); // 按任意键退出 } }
生产者使用两个注册中心 redis 和 zookeeper的
分别对外提供两种协议的接口 dubbo 和 injvm
public class Consumer1 { public static void main(String[] args) throws IOException { ApplicationConfig application = new ApplicationConfig("consumer"); List<RegistryConfig> registries = new ArrayList<RegistryConfig>(10); registries.add(new RegistryConfig("redis://127.0.0.1:6379")); registries.add(new RegistryConfig("zookeeper://127.0.0.1:2181")); ReferenceConfig<HelloService> reference = new ReferenceConfig<HelloService>(); reference.setApplication(application); reference.setRegistries(registries); reference.setInterface(HelloService.class); //使用injvm协议 reference.setScope(Constants.SCOPE_LOCAL); HelloService helloService = reference.get(); System.out.println(reference.getProtocol()); System.out.println(helloService.say("hahah")); } }
当我们使用另一个进程启动的时候 这里会抛出异常
因为两个进程不是同一个虚拟机 所以不能使用injvm协议
我们通过修改代码 在生产者中启动一个线程 去运行消费者 这样两个就会在同一个虚拟机中
public class Provider1 { public static void main(String[] args) throws IOException { ApplicationConfig app = new ApplicationConfig("provider"); List<RegistryConfig> registries = new ArrayList<RegistryConfig>(10); registries.add(new RegistryConfig("redis://127.0.0.1:6379")); registries.add(new RegistryConfig("zookeeper://127.0.0.1:2181")); List<ProtocolConfig> protocols = new ArrayList<ProtocolConfig>(10); protocols.add(new ProtocolConfig("dubbo", 20880)); protocols.add(new ProtocolConfig("injvm", 20000)); ServiceConfig<Object> service = new ServiceConfig<Object>(); service.setInterface(HelloService.class); service.setRef(new HelloServiceImpl()); service.setProtocols(protocols); service.setRegistries(registries); service.setApplication(app); service.export(); new Thread(new Consumer()).start(); System.out.println("success"); System.in.read(); // 按任意键退出 } static class Consumer implements Runnable{ public void run() { ApplicationConfig application = new ApplicationConfig("consumer"); List<RegistryConfig> registries = new ArrayList<RegistryConfig>(10); registries.add(new RegistryConfig("redis://127.0.0.1:6379")); registries.add(new RegistryConfig("zookeeper://127.0.0.1:2181")); ReferenceConfig<HelloService> reference = new ReferenceConfig<HelloService>(); reference.setApplication(application); reference.setRegistries(registries); reference.setInterface(HelloService.class); //使用injvm协议 reference.setScope(Constants.SCOPE_LOCAL); HelloService helloService = reference.get(); System.out.println(helloService.say("hahah")); } } }
此时 运行正常
在dubbo源码中有这么个注释 ,发现结果并不是这样的,在去不到jvm的情况下不会去使用别的协议
关于injvm的get set方法已经被淘汰 推荐使用 socpe
但是这里是这样注释的
相关文章推荐
- dubbo 源码学习笔记 (五) —— 注册中心模块
- dubbo 源码学习笔记 (四) —— 配置模块
- dubbo 源码学习笔记 (三) —— dubbo引用服务的过程
- dubbo 源码学习笔记 (六) —— 集群模块
- dubbo源码学习笔记----container
- dubbo 源码学习笔记 (八) —— 远程通讯模块
- dubbo源码 学习笔记(五)
- Dubbo 源码学习笔记 —— SPI的机制体现
- dubbo 源码学习笔记 (二) —— dubbo发布服务的过程
- dubbo学习笔记 一 源码编译
- dubbo源码学习笔记----RPC
- dubbo 源码学习笔记 (一) —— ExtensionLoader和URL
- dubbo源码 学习笔记(六)
- dubbo源码 学习笔记(二)
- dubbo源码学习笔记----结合Spring
- dubbo源码学习笔记----Provider和Consumer
- dubbo学习笔记(1)-注册中心和管理平台部署
- OBS源码学习笔记(一)
- BufferedInputStream 源码学习笔记
- spring 源码学习笔记(一)—— spring ioc 之加载XML转换为BeanDefinition