dubbo开发
dubbo.admin部署
解压后,放在tomcat/webapp/目录下直接运行。
这里tomcat是9090端口,访问http://127.0.0.1:9090/dubbo-admin-2.5.6/,会出现身份验证登录窗口。在WEB-INF目录下,查看dubbo.properties文件,可看到用户名密码配置以及zookeeper注册地址信息
dubbo.registry.address=zookeeper://127.0.0.1:2181
dubbo.admin.root.password=root
dubbo.admin.guest.password=guest
使用root/root登陆。
------------------------------------
dubbo-provider
1. pom.xml
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.6</version>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.5.3-beta</version>
</dependency>
<dependency>
<groupId>com.101tec</groupId>
<artifactId>zkclient</artifactId>
<version>0.10</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.8.0-alpha1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.8.0-alpha1</version>
</dependency>
<build>
<!-- <sourceDirectory>src/main/java</sourceDirectory> -->
<plugins>
<!-- 设置源文件编码方式 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<!-- <defaultLibBundleDir>lib</defaultLibBundleDir> -->
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>public</id>
<name>Public Repositories</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Snapshots</name>
<url>http://localhost:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
application.properties
dubbo.zookeeper.address=127.0.0.1:2181|127.0.0.1:2182
dubbo.hessian.port=20808
dubbo.provider.hosts=127.0.0.1
dubbo.consumer.hosts=127.0.0.1
spring-dubbo.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-3.0.xsd
http://www.springframework.org/schema/jms
http://www.springframework.org/schema/jms/spring-jms-3.0.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<!-- 提供方应用信息,用于计算依赖关系 ; 不是匹配条件,不要与提供方一样 -->
<dubbo:application name="dubbo-provider" owner="test" />
<!-- 使用zookeeper暴露服务地址 -->
<dubbo:registry protocol="zookeeper" address="${dubbo.zookeeper.address}"/>
<!-- 用dubbo协议在20881端口暴露服务 -->
<dubbo:protocol name="dubbo" port="${dubbo.hessian.port}" dispather="all" threadpool="fixed" threads="500"/>
<import resource="classpath:dubbo-provider.xml" />
</beans>
dubbo-provider.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-3.0.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<!-- 声明需要暴露的服务接口 -->
<dubbo:service interface="com.example.dubboapi.service.console.user.IDubboUserService" ref="dubboUserServiceImpl" timeout="10000" loadbalance="roundrobin" protocol="dubbo" retries="3" version="1.0.0"/>
</beans>
---------------------------------------
spring-dubbo.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:jms="http://www.springframework.org/schema/jms"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.0.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<description>Dubbo consumer配置</description>
<dubbo:application name="dubbocustomer" />
<!-- 使用zookeeper暴露服务地址 -->
<dubbo:registry protocol="zookeeper" address="${dubbo.zookeeper.address}"/>
<!-- 用dubbo协议在20881端口暴露服务 -->
<dubbo:protocol name="dubbo" port="${dubbo.hessian.port}" />
<import resource="classpath:dubbo-consumer.xml" />
</beans>
dubbo-consumer.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-3.0.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd"
default-lazy-init="true">
<dubbo:reference id="dubboUserService" interface="com.example.dubboapi.service.console.user.IDubboUserService" timeout="300000" check="false" version="1.0.0" protocol="dubbo"/>
</beans>
以上是 dubbo开发 的全部内容, 来源链接: utcz.com/z/512189.html