Dubbo项目搭建和Dubbo-admin管理平台和Zookper注册中心搭建
来源:互联网 发布:淘宝静物摄影 编辑:程序博客网 时间:2024/06/05 14:55
1.Dubbo:(Alibaba)
- 一款分布式服务框架
- 高性能和透明化的RPC远程服务调用方案
- SOA服务治理方案
2.Dubbo框架图:
框架解释:注册中心(Registry):Zookerper作为服务的注册中心
消费者(Consumer):服务调用者
提供者(Provider): 服务提供者
监控中心(Monitor):统计服务调用的次数和调用时间的监控
2.Dubbo的配置:
- 新建Maven项目,并新建Maven moudle子工程provider和consumer,在pom.xml文件中配置相关依赖的jar包和子工程依赖父工程的配置
- 配置provider子工程的resources文件中applicationprovider.xml文件
<!--使用 zookeeper 注册中心暴露服务,注意要先开启 zookeeper-->
<dubbo:registry address="zookeeper://localhost:2181"/>
<!-- 用dubbo协议在20880端口暴露服务 -->
<dubbo:protocol name="dubbo" port="20880" />
<!--使用 dubbo 协议实现定义好的 api.PermissionService 接口-->
<dubbo:service interface="com.star.dubbo.DemoService" ref="demoService" protocol="dubbo" />
<!--具体实现该接口的 bean-->
<bean id="demoService" class="com.star.dubbo.impl.DemoServiceImpl"/>
- 配置consumer子工程的resources文件H公分的applicationconsumer.xml文件
<dubbo:application name="demotest-consumer" owner="programmer" organization="dubbox"/>
<!--向 zookeeper 订阅 provider 的地址,由 zookeeper 定时推送-->
<dubbo:registry address="zookeeper://localhost:2181"/>
<!--使用 dubbo 协议调用定义好的 api.PermissionService 接口-->
<dubbo:reference id="permissionService" interface="com.star.dubbo.DemoService"/>
- 实现provider和consumer两个子工程的服务调用的接口和实现类
- 先启动Zookeeper,再启动provider,最后启动consumer(重要,重要,重要!!!)
- 最后可以通过地址栏http://localhost:8088/dubbo-admin-2.5.4-SNAPSHOT/可以查看Dubbo-Admin控制台的详细信息。
Dubbo-Admin的配置:
下载Dubbo.zip,解压后在dubbo-admin使用命令生成.war包
- mvn package -Dmaven.skip.test=true
将war包放到tomcat webapps文件夹下然后启动tomcat服务
自动解压war包到项目目录下
然后启动zookeeper,启动tomcat,然后使用上述链接即可看到后台的信息。即配置成功如下图:
如果war包无法生成,建议直接下载响应jdk版本的dubbo-admin的war包。
Dubbo封装调用:
public <T> T getDubboService(Class<T> t, String version, int timeout, boolean retries, String registryAddress, boolean validation)
{
this.log.info("consumer dubboService====class====" + t);
ReferenceConfig<T> referenceConfig = new ReferenceConfig();
referenceConfig.setApplication(this.dubboConfig.getApplication());
if ((null != registryAddress) && (registryAddress.length() > 0))
{
RegistryConfig rgsConfig = this.dubboConfig.getRegistry(registryAddress);
if (null != rgsConfig)
{
this.log.info("fileDir:" + rgsConfig.getFile());
referenceConfig.setRegistry(rgsConfig);
}
else
{
return null;
}
}
else
{
referenceConfig.setRegistry(this.dubboConfig.getRegistry());
}
referenceConfig.setInterface(t);
if (timeout > 99)
{
referenceConfig.setTimeout(Integer.valueOf(timeout));
ConsumerConfig consumer = new ConsumerConfig();
consumer.setTimeout(Integer.valueOf(timeout));
referenceConfig.setConsumer(consumer);
}
if (!retries) {
referenceConfig.setRetries(Integer.valueOf(0));
} else {
referenceConfig.setRetries(DubboPropertisConfig.DUBBO_RETRIES);
}
referenceConfig.setInjvm(Boolean.valueOf(false));
referenceConfig.setVersion(version);
referenceConfig.setProtocol("dubbo");
referenceConfig.setCheck(DubboPropertisConfig.DUBBO_CHECK);
referenceConfig.setInit(Boolean.valueOf(true));
referenceConfig.setLazy(Boolean.valueOf(false));
referenceConfig.setValidation(validation ? "true" : "false");
if (DubboPropertisConfig.DUBBO_MONITOR.booleanValue()) {
referenceConfig.setMonitor(this.dubboConfig.getMonitConfig());
}
return this.referenceConfigCache.get(referenceConfig);
}
调用示例:
ActiveRepaymentService activeRepaymentTrialService = DubboFactory.getDubboService(ActiveRepaymentService.class, "1.0.0", inputParam.getZkAdress());//调用类,版本,集群地址
阅读全文
0 0
- Dubbo项目搭建和Dubbo-admin管理平台和Zookper注册中心搭建
- Dubbo-Admin管理平台和Zookeeper注册中心的搭建
- Dubbo-Admin管理平台和Zookeeper注册中心的搭建
- Dubbo-Admin管理平台和Zookeeper注册中心的搭建
- Dubbo-Admin管理平台和Zookeeper注册中心的搭建
- Zookeeper注册中心和Dubbo-Admin管理平台的搭建
- Dubbo-Admin管理平台和Zookeeper注册中心的搭建
- Dubbo-Admin管理平台和Zookeeper注册中心的搭建
- Zookeeper注册中心和Dubbo-Admin管理平台的搭建
- Dubbo-Admin管理平台和Zookeeper注册中心的搭建
- Zookeeper注册中心和Dubbo-Admin管理平台的搭建
- Dubbo-Admin管理平台和Zookeeper注册中心的搭建
- Dubbo-Admin管理平台和Zookeeper注册中心的搭建
- Dubbo-Admin管理平台和Zookeeper注册中心的搭建
- Dubbo-Admin管理平台和Zookeeper注册中心的搭建
- Zookeeper注册中心和Dubbo-Admin管理平台的搭建
- Dubbo-Admin管理平台和Zookeeper注册中心的搭建
- Dubbo-Admin管理平台和Zookeeper注册中心的搭建
- 在阿里云服务器Ubuntu14.04 64位上安装matlab2014a
- 给定一个二叉树,返回自下而上的顺序遍历其节点值(即从左到右,从叶到根逐级)。
- Jmeter Sampler (取样器插件开发) 制定自己的 Sampler
- C#生成8位字母数字组合随机的字符串
- Educational Codeforces Round 30 B.Balanced Substring
- Dubbo项目搭建和Dubbo-admin管理平台和Zookper注册中心搭建
- 湘阴汽车站县内班车县际班车时刻表
- socket的概念和原理
- 【云栖大会】阿里巴巴发布AliGenie 语音开放平台 “智联网”战略又落一子
- spring-事务传播特性
- Jmeter之逻辑控制器(Logic Controller)
- 设计模式C++实现(7)——外观模式、组合模式
- MVC从视图传参到Controller几种方式
- Spring和hibernate集成写API进行CRUD操作