概述
provider
package com.gupao.vip.mic.dubbo.order;
public interface IOrderServices {
/*
* 下单操作
*/
DoOrderResponse doOrder(DoOrderRequest request);
}
package com.gupao.vip.mic.dubbo.order;
import org.springframework.stereotype.Service;
public class OrderServiceImpl implements IOrderServices{
public DoOrderResponse doOrder(DoOrderRequest request) {
System.out.println("曾经来过:"+request);
DoOrderResponse response=new DoOrderResponse();
response.setCode("1000");
response.setMemo("处理成功");
return response;
}
}
package com.gupao.vip.mic.dubbo.order;
import org.springframework.stereotype.Service;
public class OrderServiceImpl2 implements IOrderServices{
public DoOrderResponse doOrder(DoOrderRequest request) {
System.out.println("曾经来过 version2:"+request);
DoOrderResponse response=new DoOrderResponse();
response.setCode("1000");
response.setMemo("处理成功version2");
return response;
}
}
<?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:dubbo="http://code.alibabatech.com/schema/dubbo"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd"
>
<!--当前项目在整个分布式架构里面的唯一名称,计算依赖关系的标签-->
<dubbo:application name="order-provider" owner="mic"/>
<dubbo:monitor protocol="registry"/>
<!--dubbo这个服务所要暴露的服务地址所对应的注册中心-->
<dubbo:registry protocol="zookeeper"
address="192.168.198.200:2181,192.168.198.201:2181,192.168.198.202:2181"/>
<!--当前服务发布所依赖的协议;webserovice、Thrift、Hessain、http-->
<dubbo:protocol name="dubbo" port="20880"/>
<!--服务发布的配置,需要暴露的服务接口-->
<dubbo:service
interface="com.gupao.vip.mic.dubbo.order.IOrderServices"
ref="orderService" version="0.0.1"/>
<dubbo:service
interface="com.gupao.vip.mic.dubbo.order.IOrderServices"
ref="orderService2" version="0.0.2"/>
<!--Bean bean -->
<bean id="orderService" class="com.gupao.vip.mic.dubbo.order.OrderServiceImpl"/>
<bean id="orderService2" class="com.gupao.vip.mic.dubbo.order.OrderServiceImpl2"/>
</beans>
consumer
package com.gupao.vip.mic.dubbo.user;
import com.gupao.vip.mic.dubbo.order.DoOrderRequest;
import com.gupao.vip.mic.dubbo.order.DoOrderResponse;
import com.gupao.vip.mic.dubbo.order.IOrderServices;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.io.IOException;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args ) throws IOException {
ClassPathXmlApplicationContext context=new ClassPathXmlApplicationContext("order-consumer.xml");
//用户下单过程
IOrderServices services=
(IOrderServices)context.getBean("orderServices");
DoOrderRequest request=new DoOrderRequest();
request.setName("mic");
DoOrderResponse response=services.doOrder(request);
System.out.println(response);
//Order.doOrder();
System.in.read();
}
}
<?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: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://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<!--当前项目在整个分布式架构里面的唯一名称,计算依赖关系的标签-->
<dubbo:application name="order-provider" owner="mic"/>
<!--dubbo这个服务所要暴露的服务地址所对应的注册中心-->
<dubbo:registry address="zookeeper://192.168.198.200:2181?backup=192.168.198.201:2181,192.168.198.202:2181"/>
<!--生成一个远程服务的调用代理-->
<dubbo:reference id="orderServices"
interface="com.gupao.vip.mic.dubbo.order.IOrderServices"
version="0.0.2"/>
</beans>
最后
以上就是诚心鸡为你收集整理的dubbo-多版本的全部内容,希望文章能够帮你解决dubbo-多版本所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复