Springboot如何整合达博/管理员实现SOA案例

  介绍

这篇文章给大家分享的是有关Springboot如何整合达博/管理员实现SOA案例的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

<强>一、为啥整合达博实现SOA

达博不单单只是高性能的RPC调用框架,更是SOA服务治理的一种方案。

核心:

远程通信,向本地调用一样调用远程方法。

集群容错

服务自动发现和注册,可平滑添加或者删除服务提供者。

我们常常使用Springboot暴露HTTP服务,并走JSON模式。但慢慢量大了,一种SOA的治理方案。这样可以暴露出达博服务接口,提供给达博消费者进行RPC调用。下面我们详解下如何集成达博。

<强>二、运行springboot-dubbo-server和springboot-dubbo-client工程

运行环境:JDK 7或8,Maven 3.0 +

技术栈:Springboot 1.5 + 2.5 +达博,饲养员3.3 +

<强> 1。动物园管理员服务注册中心

管理员是一个分布式的,开放源码的分布式应用程序协调服务。它是一个为分布式应用提供一致性服务的软件,提供的功能包括:配置维护,域名服务,分布式同步,组服务等。

下载饲养员,地址http://www.apache.org/dyn/closer.cgi/zookeeper

解压饲养员

tar  zxvf  zookeeper-3.4.8.tar。广州

在conf目录新建动物园。cfg,照着该目录的zoo_sample。cfg配置如下。

cd  zookeeper-3.3.6/conf   vim  zoo.cfg

动物园。cfg代码如下(自己指定日志文件目录):

tickTime=2000   dataDir=/javaee/管理员/data    dataLogDir=/javaee/管理员/日志   clientPort=2181

在本目录下,启动动物园管理员:

cd  zookeeper-3.3.6/bin   。/zkServer.sh 开始

<强> 2。git克隆下载工程springboot-learning-example

项目地址见GitHub - https://github.com/JeffLi1993/springboot-learning-example:

git克隆git@github.com: JeffLi1993/springboot-learning-example.git

然后,Maven编译安装这个工程:

cd  springboot-learning-example   mvn  clean 安装

<强> 3。运行springboot-dubbo-server达博服务提供者工程

右键运行springboot-dubbo-server工程ServerApplication应用启动类的主要函数.Console中出现如下表示项目启动成功。这里表示达博服务已经启动成功,并注册到ZK(管理员)中。

<强> 4。运行springboot-dubbo-client达博服务消费者工程

右键运行springboot-dubbo-client工程ClientApplication应用启动类的主要函数.Console中出现如下:

…   2017 - 03 - 01,16:31:38.473  INFO  9896年,——安康;(,,,,,主要],o.s.j.e.a.AnnotationMBeanExporter ,,,:, Registering  beans  for  JMX  exposure 提醒启动   2017 - 03 - 01,16:31:38.538  INFO  9896年,——安康;(,,,,,主要],s.b.c.e.t.TomcatEmbeddedServletContainer :, Tomcat  started 提醒端口(s):, 8081, (http)   2017 - 03 - 01,16:31:38.547  INFO  9896年,——安康;(,,,,,主要],org.spring.springboot.ClientApplication :, Started  ClientApplication  6.055,拷贝seconds  (JVM  running  for  7.026)   城市{id=1, provinceId=2,, cityName=& # 39;温岭& # 39;,,描述=& # 39;是我的故乡& # 39;}

最后打印的城市信息,就是通过达博服务接口调用获取的。顺利运行成功,下面详解下各个代码及配置。

<强>三,springboot-dubbo-server和springboot-dubbo-client工程配置详解

代码都在GitHub上,https://github.com/JeffLi1993/springboot-learning-example。

<强> 1。详解springboot-dubbo-server达博服务提供者工程

springboot-dubbo-server工程目录结构

├──, pom.xml   └──src   └才能──,主要   ,,,├──,java   ,,,│,,└──,org   ,,,│,,,,└──,春天   ,,,│,,,,,,└──,springboot   ,,,│,,,,,,,,├──,ServerApplication.java   ,,,│,,,,,,,,├──,域   ,,,│,,,,,,,,│,,└──,City.java   ,,,│,,,,,,,,└──,达博   ,,,│,,,,,,,,,,├──,CityDubboService.java   ,,,│,,,,,,,,,,└──,impl   ,,,│,,,,,,,,,,,,└──,CityDubboServiceImpl.java   ,,,└──,资源   ,,,,,└──,application.properties

a.pom。xml配置

砰的一声。xml中依赖了spring-boot-starter-dubbo工程,该项目地址是https://github.com/teaey/spring-boot-starter-dubbo。

pom.xml配置如下

4.0.0 , springboot , springboot-dubbo-server , 0.0.1-SNAPSHOT , springboot-dubbo 服务端::,整合,达博/ZooKeeper 详解,SOA 案例,,   ,,,,,org.springframework.boot ,,, spring-boot-starter-parent ,,, 1.5.1.RELEASE ,,,,,,, 1.0.0 ,,,,,,,   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

Springboot如何整合达博/管理员实现SOA案例