初次体验,做个总结和记录,主要在引入依赖包的时候遇到问题多。jdk环境是1.8
添加依赖,这个依赖比较少了
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>dubbostudy2</artifactId>
<groupId>com.nn.dubbostudy2</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>server</artifactId>
<dependencies>
<!--本地的分层module的引入,model 引入了api的module-->
<dependency>
<groupId>com.zah.dubbostudy2</groupId>
<artifactId>model</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.6</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.45</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.6.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.curator/curator-framework -->
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>4.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jaxrs -->
<!--jax-rs 标准的依赖 -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.0.7.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.0.7.Final</version>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.6</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
最好先在maven的setting.xml中设置自己的本地maven库的地址。这样在后续打包发布之后consumer才可以拿到jar。
添加一个properties文件,添加一些
dubbo.reference.check=false
dubbo.registry.client=curator
dubbo.application.name=provider1
dubbo.application.owner=debug
dubbo.protocol.name=dubbo
dubbo.protocol.dubbo.port=20903
dubbo.protocol.name=rest
dubbo.protocol.rest.port=9013
dubbo.protocol.rest.server=tomcat
添加一个xml配置文件
<?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-4.3.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<!--发布出去的dubbo服务类所在包的注解-->
<dubbo:annotation package="com.zah.dubbostudy2.service.dubbo" />
<!--注册中心zookeeper配置信息-->
<dubbo:registry address="zookeeper://127.0.0.1:2181" />
<!--支持两种协议的调用:rpc-dubbo协议;http协议-rest api-url调用-->
<dubbo:protocol name="rest" threads="500" contextpath="v1" server="tomcat" accepts="500" port="9013"/>
<dubbo:protocol name="dubbo" port="20903"/>
<!--消费方信息配置-->
<dubbo:application name="consumer1" owner="debug" organization="dubbox"/>
</beans>
网上有的xml,注解的不能够被引用。这个没有问题,都是测试通过的。
然后配置一下消费者方的文件,properties文件都差不多,就是端口号和名称改一下
dubbo.reference.check=false
dubbo.registry.client=curator
dubbo.application.name=provider2
dubbo.application.owner=debug
添加配置文件xml
<?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-4.3.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<!--发布出去的dubbo服务类所在包的注解-->
<dubbo:annotation package="com.nn.dubbostudy3.server.service.dubbo" />
<!--注册中心zookeeper配置信息-->
<dubbo:registry address="zookeeper://127.0.0.1:2181" />
<!--支持两种协议的调用:rpc-dubbo协议;http协议-rest api-url调用-->
<dubbo:protocol name="rest" threads="500" contextpath="v1" server="tomcat" accepts="500" port="9014"/>
<dubbo:protocol name="dubbo" port="20904"/>
<!--消费方信息配置-->
<dubbo:application name="consumer2" owner="debug" organization="dubbox"/>
<!--deploy content-->
<dubbo:reference id="dubboItemService" interface="com.nn.project.service.IDubboItemService"
protocol="dubbo" version="1.0" timeout="20000"/>
</beans>
其它问题就比较容易解决了。
dubbo 的控制台搭建
官网http://dubbo.apache.org/zh-cn/docs/admin/introduction.html
按照操作使用maven构建。
如果发现tomcat端口被占用,windows下
netstat -ano|findstr 8080
taskkill /pid 55565 /f
此文是慕课网的
2小时实战Apache顶级项目-RPC框架Dubb
的同堂练习
网友评论