Spring整合Dubbo对外提供服务
来源:互联网 发布:淘宝微淘动态 编辑:程序博客网 时间:2024/05/22 23:28
1.添加依赖
/*dubbox*/compile group: 'com.alibaba', name: 'dubbo', version: '2.5.3'compile "io.netty:netty:3.7.0.Final"/*zookeeper客户端*/compile "com.github.sgroschupf:zkclient:0.1"
2.创建dubbo.properties,配置dubbo相关信息
dubbo.appname=shopmanagedubbo.registry.protocol=zookeeper#zookeeper的地址和端口,默认为2181dubbo.registry.address=127.0.0.1:29181dubbo.registry.file=./logs/registry/user-dubbo-registry.cache#dubbo协议端口dubbo.protocol.port=20883#通信协议选择dubbo,也可以使用rest等dubbo.protocol=dubbodubbo.provider.timeout=200000
3.创建dubbo-privoder.xml,声明暴露服务
可以参考DUBBO官网中的provider.xml内容。
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:lang="http://www.springframework.org/schema/lang" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <!-- 加载配置文件 --> <bean id="dubboConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="order" value="1" /> <property name="ignoreUnresolvablePlaceholders" value="true" /> <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /> <property name="locations" value="classpath:dubbo/dubbo.properties" /> </bean> <dubbo:application name="${dubbo.appname}" /> <dubbo:registry protocol="${dubbo.registry.protocol}" address="${dubbo.registry.address}" file="${dubbo.registry.file}" /> <dubbo:protocol name="${dubbo.protocol}" port="${dubbo.protocol.port}"/> <dubbo:provider timeout="${dubbo.provider.timeout}" retries="0" threads="300" /> <!-- 声明需要暴露的服务接口 --> <dubbo:service interface="com.ai.gcf.api.emall.productmanage.interfaces.IProductManageQueyDubboSV" ref="iProductManageQueyDubboSV" /> <!-- 和本地bean一样实现服务 --> <bean id="iProductManageQueyDubboSV" class="com.ai.emall.api.productmanage.impl.ProductManageQueyDubboSVImpl" /> <!-- 引入之前的spring配置文件 --> <import resource="../springContext.xml" /></beans>
4.编写main方法启动服务
public class DubboStart { public static void main(String[] args) { //加载配置文件 System.setProperty(SpringContainer.SPRING_CONFIG, "classpath*:dubbo/dubbo-provider.xml"); Main.main(args); }}
ok,至此之前的查询接口(IProductManageQueyDubboSV)已经通过Dubbo暴露出来了。
5.测试IProductManageQueyDubboSV服务是否已经注册成功。
前提启动zookeeper,运行main方法。
当打印出Dubbo service server started!表示启动成功。
6.打开cmd,输入下面命令(注意端口为通信协议端口,而不是连接zookeeper的端口):
telnet 127.0.0.1 20883
telnet成功后,就可以输入dubbo命令了
ls
其他dubbo命令可以参考官方文档。
DUBBO命令中个人认为最好使用的是invoke方法,可以自己调用,尤其是在开发环境,省去写test,打个断点,然后invoke调用,直接可以调试。
阅读全文
0 0
- Spring整合Dubbo对外提供服务
- 如何让虚拟机对外提供服务
- java对外提供服务接口如何写?
- 【Dubbo实战】 Dubbo+Zookeeper+Spring整合应用篇-Dubbo基于Zookeeper实现分布式服务(二)
- 【Dubbo实战】 Dubbo+Zookeeper+Spring整合应用篇-Dubbo基于Zookeeper实现分布式服务(二)
- 【Dubbo实战】 Dubbo+Zookeeper+Spring整合应用篇-Dubbo基于Zookeeper实现分布式服务(二)
- 【Dubbo实战】 Dubbo+Zookeeper+Spring整合应用篇-Dubbo基于Zookeeper实现分布式服务(二)
- 【Dubbo实战】 Dubbo+Zookeeper+Spring整合应用篇-Dubbo基于Zookeeper实现分布式服务(二)
- 【Dubbo实战】 Dubbo+Zookeeper+Spring整合应用篇-Dubbo基于Zookeeper实现分布式服务(二)
- dubbo实例 Dubbo+Zookeeper+Spring整合应用篇-Dubbo基于Zookeeper实现分布式服务
- 【Dubbo实战】 Dubbo+Zookeeper+Spring整合应用篇-Dubbo基于Zookeeper实现分布式服务
- 【Dubbo实战】 Dubbo+Zookeeper+Spring整合应用篇-Dubbo基于Zookeeper实现分布式服务(二)
- 【Dubbo实战】 Dubbo+Zookeeper+Spring整合应用篇-Dubbo基于Zookeeper实现分布式服务(二)
- spring整合dubbo+zookeeper搭分布式服务,简单案例
- dubbo与spring整合使用(服务与引用)
- Spring-boot:5分钟整合Dubbo构建分布式服务
- ubuntu安装dubbo服务提供
- spring+dubbo整合
- map/set/multi_map/multi_set/unorder_map/unorder_set总结
- jquery---组件高效的数字滚动特效
- css动画
- 使用Jadx反编译apk
- 【LeetCode】41. First Missing Positive
- Spring整合Dubbo对外提供服务
- POJ 1259 The Picnic 笔记
- 使用jquery.fullpage.js需要动态改变导航小圆点的样式
- could not reserve enough space for object heap
- 数据挖掘-层次聚类·单身狗问题分析
- u-boot代码分析
- angularjs实现一个应用小程序
- Head First Jsp&Servlet笔记01 入门
- 利用keras搭建自编码器网络——脑机接口