消费者这块不过多的讲解上图
消费者的配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 -->
<dubbo:application name="edu-service-user" />
<!-- 使用zookeeper注册中心暴露服务地址 -->
<!-- <dubbo:registry address="multicast://224.5.6.7:1234" /> -->
<dubbo:registry address="zookeeper://127.0.0.1:2181" />
<!-- 生成远程服务代理,可以像使用本地bean一样使用demoService -->
<dubbo:reference id="userService" interface="com.provider.DemoService" />
</beans>
测试消费者
package test;
import com.provider.DemoService;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class test {
public static void main(String[] args) throws Exception {
//读取配置文件
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"dubbo-service.xml"});
//获取在zookeeper注册的服务接口
DemoService helloService = (DemoService)context.getBean("userService");
//调用接口
System.out.println("HelloService = " + helloService.getPermissions(12L));
//不让控制台消失,按任意键结束
System.in.read();
}
}