dubbo rpc服务使用

1、用maven命令编译dubbo-master项目,注意,一定要用jdk7,jdk8会报错,错误如下:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productionModeSensiblePostProcessor': Cannot create inner bean '(inner bean)' of type [com.alibaba.citrus.springext.util.SpringExtUtil$ConstructorArg] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#11': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'registryService': Instantiation of bean failed; nested exception is java.lang.ExceptionInInitializerError

完成后将dubbo-admin-2.5.4-SNAPSHOT.war部署到tomcat下



2、安装zookper,win下直接下载就可以运行。


3、写个provide端项目,生产者,写个service接口。并实现


配置文件application.xml


扫描二维码关注公众号,回复: 2236125 查看本文章

<?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
http://code.alibabatech.com/schema/dubbo ">
    <!-- 具体的实现bean -->
    <bean id="testService" class="com.dubbotest.service.impl.TestServiceImpl"/>
    <!-- 提供方应用信息,用于计算依赖关系 -->
    <dubbo:application name="provider"/>
    <!-- 使用zookeeper注册中心暴露服务地址 -->
    <dubbo:registry address="zookeeper://127.0.0.1:2181"/>
    <!-- 用dubbo协议在20880端口暴露服务 -->
    <dubbo:protocol name="dubbo" port="29014"/>
    <!-- 声明需要暴露的服务接口 -->
    <dubbo:service interface="com.dubbotest.service.TestService" ref="testService"/>
</beans>


4、写consumer项目,作为客户端

配置文件:

<?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="consumer" />
    <!-- 使用multicast广播注册中心暴露发现服务地址 -->
    <dubbo:registry  protocol="zookeeper" address="zookeeper://127.0.0.1:2181" />
    <!-- 生成远程服务代理,可以和本地bean一样使用 -->
    <dubbo:reference id="testService" interface="com.dubbotest.service.TestService" />
</beans> 


注意consumer项目要依赖之前的provide项目,pom.xml文件中要写好依赖项。

 <dependency>  
          <groupId>com.dubbotest</groupId>  
          <artifactId>provider</artifactId>  
          <version>0.0.1-SNAPSHOT</version>  
      </dependency>  

5、分步启动

1、启动zookper

2、启动tomcat的dubbo-admin

3、运行provide,这时可以在dubbo-admin这个web项目上看到provide这个项目已经提供服务

4、运行consumer,可以看到消费项目consumer运行起来了。


时间比较仓促,先简单写个步骤,以后有空来填。





猜你喜欢

转载自blog.csdn.net/cardinalzbk/article/details/70230930