主要是以下几个步骤:
1. 安装Zookeeper,启动;
2. 创建MAVEN项目,构建Dubbo+Zookeeper+Spring实现的简单Demo;
3. 安装Dubbo-admin,实现监控。
一,配置文件
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-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="com.ielpm.pay.core.provider" owner="ielpm-pay-core" organization="ielpm"/>
<dubbo:registry address="zookeeper://localhost:2181" timeout='60000'/>
<dubbo:protocol name="dubbo" serialization="kryo" port="20885" accesslog="/home/core/tomcat-core/logs/core-dubbo.log"/>
<!-- 服务 -->
<dubbo:service interface="com.alibaba.dubbo.service.ProviderService" ref="demoService" cluster="failfast" />
<bean id="demoService" class="com.alibaba.dubbo.service.impl.ProviderServiceImpl"/>
</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-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<!--定义了提供方应用信息,用于计算依赖关系;在 dubbo-admin 或 dubbo-monitor 会显示这个名字,方便辨识-->
<dubbo:application name="com.ielpm.pay.paygate.consumer" owner="ielpm-pay-paygate" organization="ielpm"/>
<!--使用 zookeeper 注册中心暴露服务,注意要先开启 zookeeper-->
<dubbo:registry address="zookeeper://localhost:2181" timeout="60000"/>
<dubbo:consumer check="false"/>
<!-- 用dubbo协议在20882端口暴露服务 -->
<dubbo:protocol name="dubbo" serialization="kryo" port="20882" />
<!--使用 dubbo 协议实现定义好的ProviderService 接口-->
<dubbo:reference id="providerService" interface="com.alibaba.dubbo.service.ProviderService" timeout="20000"/>
</beans>
二,springboot启动类中加载dubbo配置文件:
1)dubbo提供方
@SpringBootApplication
@EnableAutoConfiguration
@ImportResource({ "classpath:META-INF/spring/dubbo-provider-cfg.xml" })
@ComponentScan("com.alibaba")
public class DubboApplication {
public static void main(String[] args) {
SpringApplication.run(DubboApplication.class, args);
}
}
2)dubbo消费方
@SpringBootApplication
@EnableAutoConfiguration
@ImportResource({ "classpath:META-INF/spring/dubbo-consumer-cfg.xml" })
@ComponentScan("com.alibaba")
public class DubboApplication {
public static void main(String[] args) {
SpringApplication.run(DubboApplication.class, args);
}
三,dubbo消费者方pom文件中引入dubbo服务提供方的服务的jar
在dubbo consumer项目的pom.xml文件中加入
<!-- 引入dubbo provider提供的服务的jar start -->
<dependency>
<groupId>com.alibaba.dubbo</groupId>
<artifactId>service</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- 引入dubbo provider提供的服务的jar end -->
三,Dubbo管理控制台
下载dubbo-admin,可自行根据网上介绍安装。大致做法就是将dubbo-admin中 的某个文件夹内容替换到tomcat的conf中,再运行tomcat即可。
1. 安装Zookeeper,启动;
2. 创建MAVEN项目,构建Dubbo+Zookeeper+Spring实现的简单Demo;
3. 安装Dubbo-admin,实现监控。
一,配置文件
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-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="com.ielpm.pay.core.provider" owner="ielpm-pay-core" organization="ielpm"/>
<dubbo:registry address="zookeeper://localhost:2181" timeout='60000'/>
<dubbo:protocol name="dubbo" serialization="kryo" port="20885" accesslog="/home/core/tomcat-core/logs/core-dubbo.log"/>
<!-- 服务 -->
<dubbo:service interface="com.alibaba.dubbo.service.ProviderService" ref="demoService" cluster="failfast" />
<bean id="demoService" class="com.alibaba.dubbo.service.impl.ProviderServiceImpl"/>
</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-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<!--定义了提供方应用信息,用于计算依赖关系;在 dubbo-admin 或 dubbo-monitor 会显示这个名字,方便辨识-->
<dubbo:application name="com.ielpm.pay.paygate.consumer" owner="ielpm-pay-paygate" organization="ielpm"/>
<!--使用 zookeeper 注册中心暴露服务,注意要先开启 zookeeper-->
<dubbo:registry address="zookeeper://localhost:2181" timeout="60000"/>
<dubbo:consumer check="false"/>
<!-- 用dubbo协议在20882端口暴露服务 -->
<dubbo:protocol name="dubbo" serialization="kryo" port="20882" />
<!--使用 dubbo 协议实现定义好的ProviderService 接口-->
<dubbo:reference id="providerService" interface="com.alibaba.dubbo.service.ProviderService" timeout="20000"/>
</beans>
二,springboot启动类中加载dubbo配置文件:
1)dubbo提供方
@SpringBootApplication
@EnableAutoConfiguration
@ImportResource({ "classpath:META-INF/spring/dubbo-provider-cfg.xml" })
@ComponentScan("com.alibaba")
public class DubboApplication {
public static void main(String[] args) {
SpringApplication.run(DubboApplication.class, args);
}
}
2)dubbo消费方
@SpringBootApplication
@EnableAutoConfiguration
@ImportResource({ "classpath:META-INF/spring/dubbo-consumer-cfg.xml" })
@ComponentScan("com.alibaba")
public class DubboApplication {
public static void main(String[] args) {
SpringApplication.run(DubboApplication.class, args);
}
三,dubbo消费者方pom文件中引入dubbo服务提供方的服务的jar
在dubbo consumer项目的pom.xml文件中加入
<!-- 引入dubbo provider提供的服务的jar start -->
<dependency>
<groupId>com.alibaba.dubbo</groupId>
<artifactId>service</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- 引入dubbo provider提供的服务的jar end -->
三,Dubbo管理控制台
下载dubbo-admin,可自行根据网上介绍安装。大致做法就是将dubbo-admin中 的某个文件夹内容替换到tomcat的conf中,再运行tomcat即可。