demo

demo

项目中开发一个对外服务接口及消费实例:

Dubbo采用全Spring配置方式,透明化接入应用,对应用没有任何API侵入,只需用Spring加载Dubbo的配置即可,Dubbo基于Spring的Schema扩展进行加载。

服务提供者

一、在DubboAPI中写入接口

二、服务提供方:实现此接口

三、服务提供方:用Spring配置声明暴露服务

服务消费者

四、服务消费方:通过Spring配置订阅该服务

五、服务消费方:使用IoC注入,并调用远程服务

项目Dubbo相关公共配置

web.xml配置

pom.xml配置依赖的jar

Dubbo服务者消费者控制中心

// 获取远程服务代理

// IDemoService demoService = (IDemoService)SpringConfigHelper.getBean("demoService");

//

// String hello = demoService.sayHello("world"); // 执行远程方法

// System.out.println(hello);

服务提供者

服务消费者

Dubbo :

一、本地直联

1、调用方
<dubbo:reference id="demoService"  
        interface="cn.com.eju.deal.dubbo.demo.api.IDemoService" check="false" url="dubbo://172.28.136.191:20881" />   对方服务Url

2、生产者
    <!-- 暴露远程服务配置  声明需要暴露的服务接口 -->
    <bean id="areaService" class="cn.com.eju.deal.dubbo.impl.AreaServiceImpl" />
    <dubbo:service interface="cn.com.eju.deal.dubbo.op.api.IAreaService"
        ref="areaService"  token="true" />   红色拿掉

二、多服务部署在一台机子上

Last updated

Was this helpful?