Springboot 整合 Dubbo/ZooKeeper 详解 SOA 案例
一、为啥整合 Dubbo 实现 SOA二、运行 springboot-dubbo-server 和 springboot-dubbo-client 工程三、springboot-dubbo-server 和 springboot-dubbo-client 工程配置详解
一、为啥整合 Dubbo 实现 SOA
二、运行 springboot-dubbo-server 和 springboot-dubbo-client 工程
|
1
|
tar zxvf zookeeper-3.4.8.tar.gz |
|
1
2
|
cd zookeeper-3.3.6/confvim zoo.cfg |
|
1
2
3
4
|
tickTime=2000dataDir=/javaee/zookeeper/data dataLogDir=/javaee/zookeeper/logclientPort=2181 |
|
1
2
|
cd zookeeper-3.3.6/bin./zkServer.sh start |
|
1
2
|
cd springboot-learning-examplemvn clean install |

|
1
2
3
4
5
|
...2017-03-01 16:31:38.473 INFO 9896 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup2017-03-01 16:31:38.538 INFO 9896 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8081 (http)2017-03-01 16:31:38.547 INFO 9896 --- [ main] org.spring.springboot.ClientApplication : Started ClientApplication in 6.055 seconds (JVM running for 7.026)City{id=1, provinceId=2, cityName='温岭', description='是我的故乡'} |
三、springboot-dubbo-server 和 springboot-dubbo-client 工程配置详解
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
├── pom.xml└── src └── main ├── java │ └── org │ └── spring │ └── springboot │ ├── ServerApplication.java │ ├── domain │ │ └── City.java │ └── dubbo │ ├── CityDubboService.java │ └── impl │ └── CityDubboServiceImpl.java └── resources └── application.properties |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>springboot</groupId> <artifactId>springboot-dubbo-server</artifactId> <version>0.0.1-SNAPSHOT</version> <name>springboot-dubbo 服务端:: 整合 Dubbo/ZooKeeper 详解 SOA 案例</name> <!-- Spring Boot 启动父依赖 --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.1.RELEASE</version> </parent> <properties> <dubbo-spring-boot>1.0.0</dubbo-spring-boot> </properties> <dependencies> <!-- Spring Boot Dubbo 依赖 --> <dependency> <groupId>io.dubbo.springboot</groupId> <artifactId>spring-boot-starter-dubbo</artifactId> <version>${dubbo-spring-boot}</version> </dependency> <!-- Spring Boot Web 依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- Spring Boot Test 依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!-- Junit --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency> </dependencies></project> |
|
1
2
3
4
5
6
|
## Dubbo 服务提供者配置spring.dubbo.application.name=providerspring.dubbo.registry.address=zookeeper://127.0.0.1:2181spring.dubbo.protocol.name=dubbospring.dubbo.protocol.port=20880spring.dubbo.scan=org.spring.springboot.dubbo |
|
1
2
3
4
5
6
7
8
|
// 注册为 Dubbo 服务@Service(version = "1.0.0")public class CityDubboServiceImpl implements CityDubboService { public City findCityByName(String cityName) { return new City(1L,2L,"温岭","是我的故乡"); }} |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
├── pom.xml└── src └── main ├── java │ └── org │ └── spring │ └── springboot │ ├── ClientApplication.java │ ├── domain │ │ └── City.java │ └── dubbo │ ├── CityDubboConsumerService.java │ └── CityDubboService.java └── resources └── application.properties |
|
1
2
3
4
5
6
7
|
## 避免和 server 工程端口冲突server.port=8081## Dubbo 服务消费者配置spring.dubbo.application.name=consumerspring.dubbo.registry.address=zookeeper://127.0.0.1:2181spring.dubbo.scan=org.spring.springboot.dubbo |
|
1
2
3
4
5
6
7
8
9
10
11
12
|
@Componentpublic class CityDubboConsumerService { @Reference(version = "1.0.0") CityDubboService cityDubboService; public void printCity() { String cityName="温岭"; City city = cityDubboService.findCityByName(cityName); System.out.println(city.toString()); }} |
|
1
2
3
4
5
6
7
8
9
10
11
|
@SpringBootApplicationpublic class ClientApplication { public static void main(String[] args) { // 程序启动入口 // 启动嵌入式的 Tomcat 并初始化 Spring 环境及其各 Spring 组件 ConfigurableApplicationContext run = SpringApplication.run(ClientApplication.class, args); CityDubboConsumerService cityService = run.getBean(CityDubboConsumerService.class); cityService.printCity(); }} |
四、小结

Springboot 整合 Dubbo/ZooKeeper 详解 SOA 案例的更多相关文章
- springboot整合dubbo+zookeeper最新详细
引入 最近和小伙伴做一个比赛,处于开发阶段,因为涉及的服务比较多,且服务需要分开部署在不同的服务器上,讨论之后,打算采用分布式来做,之前学习springboot的时候,部分章节涉及到了springbo ...
- springboot整合dubbo\zookeeper做注册中心
springboot整合dubbo发布服务,zookeeper做注册中心.前期的安装zookeeper以及启动zookeeper集群就不说了. dubbo-admin-2.5.4.war:dubbo服 ...
- SpringBoot整合JWT实战详解
jwt 介绍就不多说了,下面通过代码演示开发过程中jwt 的使用. (1)在pom.xml中引入对应的jar <dependency> <groupId>io.jsonwebt ...
- SpringBoot整合dubbo(yml格式配置)
yml文件 如果只作为服务的消费者不用暴露端口号,扫描的包名根据自己service改 dubbo: application: name: springboot-dubbo-demo #应用名 regi ...
- Springboot整合Dubbo和Zookeeper
Dubbo是一款由阿里巴巴开发的远程服务调用框架(RPC),其可以透明化的调用远程服务,就像调用本地服务一样简单.截至目前,Dubbo发布了基于Spring Boot构建的版本,版本号为0.2.0,这 ...
- SpringBoot配置文件 application.properties详解
SpringBoot配置文件 application.properties详解 本文转载:https://www.cnblogs.com/louby/p/8565027.html 阅读过程中若发现 ...
- Springboot整合log4j2日志全解
目录 常用日志框架 日志门面slf4j 为什么选用log4j2 整合步骤 引入Jar包 配置文件 配置文件模版 配置参数简介 Log4j2配置详解 简单使用 使用lombok工具简化创建Logger类 ...
- 【转】SpringBoot学习笔记(7) SpringBoot整合Dubbo(使用yml配置)
http://blog.csdn.net/a67474506/article/details/61640548 Dubbo是什么东西我这里就不详细介绍了,自己可以去谷歌 SpringBoot整合Dub ...
- SPRINGBOOT注解最全详解(
# SPRINGBOOT注解最全详解(整合超详细版本) 使用注解的优势: 1.采用纯java代码,不在需要配置繁杂的xml文件 ...
随机推荐
- App外包开发周期一般多长?
很多人问我,开发一个app要用多长时间.事实上开发一款app没有固定周期的,得因产品而论,你软件的功能需求决定了app外包开发的周期.但是除了app本身以外,人为因素往往对开发周期也有一定的影响.例如 ...
- centos 修改/etc/fstab后无法启动
今天做实验,增加了一个磁盘sdb1,而且也增加了自动挂载的功能/etc/fstab里增加了记录. 重新启动服务器的时候,系统启动不了了. 系统提示: 按提示 输入 root的密码,进入以Repair ...
- 2.13.1. 对结果排序(Core Data 应用程序实践指南)
传递NSSortDescriptor给NSFetchRequest进行排序.示例如下,修改demo方法: NSSortDescriptor *sort = [NSSortDescriptor sort ...
- C# is 运算符
is 运算符并不是说明对象是某种类型的一种方式,而是可以检查对象是否是给定的类型,或者是否可以转换为给定的类型,如果是,这个运算符就返回true.is 运算符的语法如下: <operand> ...
- easyUI linkbutton组件
easyUI linkbutton组件: <!DOCTYPE html> <html lang="en"> <head> <meta ch ...
- 二分查找 - vb.net
Module Module1 Sub Main() Dim array(999) As Integer Dim searchValue As Integer ...
- js实现360度图片旋转
▓▓▓▓▓▓ 大致介绍 这次是一个简单的效果,就是思路的问题 效果: ▓▓▓▓▓▓ 思路 旋转的效果就是根据鼠标的的移动距离来显示不同的图片,形成视觉差,仿佛就是在正真的旋转 由于效果是根据鼠标的移动 ...
- CodeForces757B
B. Bash's Big Day time limit per test 2 seconds memory limit per test 512 megabytes input standard i ...
- CodeForces757A
A. Gotta Catch Em' All! time limit per test 1 second memory limit per test 256 megabytes input stand ...
- 开源OSS.Social项目进阶介绍和使用展示
在开源OSS.Social微信项目解析的随笔中,我简单给大家分享了进行中微信项目的概要设计,没有全局介绍,没有详细讲解,也没有如何使用,很多朋友估计匆匆一瞥就忙着抢开工红包去了.本着不能马虎的态度,这 ...