Apache Dubbo 是一款高性能、轻量级的开源服务框架。提供了六大核心能力:面向接口代理的高性能RPC调用,智能容错和负载均衡,服务自动注册和发现,高度可扩展能力,运行期流量调度,可视化的服务治理与运维。 一、Dubbo如何实现远程通信?
服务消费者去注册中心订阅到服务提供者的信息。然后通过dubbo进行远程调用。
3、创建my-dubbo-demo的module,类型为maven 命名device-service-providerpom.xml
<?xml version="1.0" encoding="UTF-8"?>
编写具体的提供服务的实现类
编写bean配置文件,将dubbo和spring ioc整合,把服务提供到dubbo中.provider.xml
<?xml version="1.0" encoding="UTF-8"?>
package com.hao.device.service.impl;import org.springframework.context.support.ClassPathXmlApplicationContext;import java.io.IOException;public class Provider { public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"provider.xml"}); context.start(); System.out.println("服务已注册!"); try { // 按任意键退出 System.in.read(); } catch (IOException e) { e.printStackTrace(); } }}
4、创建my-dubbo-demo的module,类型为maven 命名device-service-consumerpom.xml<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
package com.hao.device.consumer;import com.hao.service.api.device.DeviceService;import org.springframework.context.support.ClassPathXmlApplicationContext;public class Consumer { public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"consumer.xml"}); context.start(); DeviceService deviceService = (DeviceService) context.getBean("deviceService"); String result = deviceService.getDeviceNameByID(1001); System.out.println(result); }}
三、服务代理过程