Dubbo的应用
导语:Dubbo是阿里巴巴的一个分布式服务的开源框架,致力于提供高性能和透明化的RPC远程服务调用方案,是阿里巴巴SOA服务化治理方案的核心框架,每天为2,000+个服务提供3,000,000,000+次访问量支持,并被广泛应用于阿里巴巴集团的各成员站点。
- dubbo.registry.address=zookeeper://127.0.0.1:2181
- dubbo.admin.root.password=root
- dubbo.admin.guest.password=guest
# The number of milliseconds of each tick tickTime=2000 # The number of ticks that the initial # synchronization phase can take initLimit=10 # The number of ticks that can pass between # sending a request and getting an acknowledgement syncLimit=5 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. dataDir=/home/xudan/zookeeper-3.4.6/data #myid文件存放的路径 dataLogDir=/home/xudan/zookeeper-3.4.6/logs #日志存放路径 # the port at which the clients will connect clientPort=2181 # the maximum number of client connections. # increase this if you need to handle more clients #maxClientCnxns=60 # # Be sure to read the maintenance section of the # administrator guide before turning on autopurge. # # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance # # The number of snapshots to retain in dataDir #autopurge.snapRetainCount=3 # Purge task interval in hours # Set to "0" to disable auto purge feature #autopurge.purgeInterval=1 server.1=Master:2555:3555 server.2=Slave1:2556:3556 server.3=Slave2:2557:3557 |
mkdir data
mkdir logs
touch /data/myid
echo 1 > /home/lgp/ zookeeper-3.4.6/data/myid //设置myid的值为1
yum -y install openssh-clients
修改对应 myid ,etc/hosts
scp /home/lgp/zookeeper-3.4.6 192.168.1.81:/home/lgp //跨机器复制
启动服务:
service iptables stop:分别关闭对应机器的 iptables
cd /home/lgp/zookeeper-3.4.6/bin
./bin/zkServer.sh start :开启zookeeper
./bin/zkServer.sh status :状态查询
./bin/zkServer.sh stop :关闭zookeeper
vi dubbo.properties
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.3</version>
</dependency>
<!-- Zookeeper 用于分布式服务管理 -->
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.5</version>
</dependency>
<dependency>
<groupId>com.101tec</groupId>
<artifactId>zkclient</artifactId>
<version>0.3</version>
</dependency>
<!-- Zookeeper 用于分布式服务管理 end -->
<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="guduo-service-user" />
<!-- 使用zookeeper注册中心暴露服务地址 -->
<dubbo:registry protocol="zookeeper" address="${dubbo.registry.address}" />
<!—本机 -->
<dubbo:protocol name="dubbo" port="20823" />
<!-- 监控中心配置,protocol="registry",表示从注册中心发现监控中心地址 -->
<dubbo:monitor protocol="registry"/>
<!-- 当ProtocolConfig和ServiceConfig某属性没有配置时,采用此缺省值 -->
<dubbo:provider timeout="30000" threadpool="fixed" threads="100" accepts="1000" />
<!-- 服务接口 -->
<dubbo:service retries="0" interface="com.guduo.service.system.UserReportService" ref="userReportService" />
<dubbo:service retries="0" interface="com.guduo.service.system.UserSuggestionService" ref="userSuggestionService" />
</beans>
<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="guduo-web-publish" />
<!-- 使用zookeeper注册中心暴露服务地址 -->
<!-- 注册中心地址 -->
<dubbo:registry protocol="zookeeper" address="${dubbo.registry.address}" />
<!-- 用户服务接口 -->
<dubbo:reference interface="com.guduo.service.user.PmsActionService" id="pmsActionService" check="false"/>
<dubbo:reference interface="com.guduo.service.user.PmsMenuService" id="pmsMenuService" check="false"/>
</beans>
import org.apache.commons.logging.LogFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
*
* @描述: 启动Dubbo服务用的MainClass.
* @作者: 刘广平
* @创建时间: 2016-9-5,下午9:47:55 .
* @版本: 1.0 .
*/
public class DubboProvider {
private static final Log log = LogFactory.getLog(DubboProvider.class);
public static void main(String[] args) {
try {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring/spring-context.xml");
context.start();
} catch (Exception e) {
log.error("== DubboProvider context start error:",e);
}
synchronized (DubboProvider.class) {
while (true) {
try {
DubboProvider.class.wait();
} catch (InterruptedException e) {
log.error("== synchronized error:",e);
}
}
}
}
}
最新文章
- c#操作MangoDB 之MangoDB CSharp Driver驱动详解
- DB2数据库中SQL语句中使用or和and的关键字的时候注意事项
- 简单的将内容加入到drupal的主页面
- 跟我学 NHibernate (二)
- USACO Section 2.3 奶牛家谱 Cow Pedigrees
- Semi-definite programming优化工具
- Android 自定义控件 EditText输入框两边加减按钮Button
- SQL学习笔记——SQL中的数据查询语句汇总
- vmware重装系统后虚拟机实例文件*.vmdk重用
- Cocoapod安装使用
- 一篇入门的php Class 文章
- Python 显示LinkedIn用户作业
- android Instrumentoation 问答
- TransactionTemplate编程式事务管理方式的进阶使用---自定义拓展模板类
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
- 从外面更新unity需要用的题库
- WPF触发器(Trigger) - DataTrigger
- Codeforces 269C Flawed Flow (看题解)
- JS中的的";闭包";?深入Javascript之this
- [SoapUI] How to create a random UUID in each Request&#39;s Headers