博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Motan-Zookeper分布式项目搭建
阅读量:6429 次
发布时间:2019-06-23

本文共 15708 字,大约阅读时间需要 52 分钟。

1. 新建maven项目motan-zookeper及module

2. 添加模块之间的依赖

2.1   motan-zookeper.pom

1 
2
5
4.0.0
6 7
com.motan.zookeper
8
motan-zookeper
9
pom
10
1.0-SNAPSHOT
11
12
motan-zookeper-api
13
motan-zookeper-model
14
motan-zookeper-service
15
motan-zookeper-web
16
17 18
19
org.springframework.boot
20
spring-boot-starter-parent
21
1.5.7.RELEASE
22
23
24
25
org.projectlombok
26
lombok
27
1.16.18
28
29
30 31
32
33
34
org.springframework.boot
35
spring-boot-maven-plugin
36
37
38
39
repackage
40
41
42
43
44
true
45
46
47
48
49 50
View Code

2.2   motan-zookeper-api.pom

1 
2
5
6
motan-zookeper
7
com.motan.zookeper
8
1.0-SNAPSHOT
9
10
4.0.0
11 12
motan-zookeper-api
13 14
View Code

2.3   motan-zookeper-model.pom

1 
2
5
6
motan-zookeper
7
com.motan.zookeper
8
1.0-SNAPSHOT
9
10
4.0.0
11 12
motan-zookeper-model
13 14
15
16
org.springframework.boot
17
spring-boot-starter-data-jpa
18
19
20
View Code

2.4   motan-zookeper-service.pom

1 
2
5
6
motan-zookeper
7
com.motan.zookeper
8
1.0-SNAPSHOT
9
10
4.0.0
11 12
motan-zookeper-service
13 14
15
16
17
org.springframework.boot
18
spring-boot-starter
19
20
21
22
org.springframework.boot
23
spring-boot-starter-actuator
24
25
26
27
org.springframework.boot
28
spring-boot-starter-data-jpa
29
30
31
32
mysql
33
mysql-connector-java
34
35
36
37
com.googlecode.log4jdbc
38
log4jdbc
39
1.2
40
41
42
43
com.weibo
44
motan-core
45
0.2.2
46
47
48
49
com.weibo
50
motan-transport-netty
51
0.2.2
52
53
54
55
com.weibo
56
motan-springsupport
57
0.2.1
58
59
60
61
com.weibo
62
motan-registry-zookeeper
63
0.2.1
64
65
66
ma.glasnost.orika
67
orika-core
68
1.5.1
69
70 71
72
73
com.motan.zookeper
74
motan-zookeper-api
75
1.0-SNAPSHOT
76
compile
77
78
79
com.motan.zookeper
80
motan-zookeper-model
81
1.0-SNAPSHOT
82
compile
83
84
85
View Code

2.5   motan-zookeper-web.pom

1 
2
5
6
motan-zookeper
7
com.motan.zookeper
8
1.0-SNAPSHOT
9
10
4.0.0
11 12
motan-zookeper-web
13 14
15
16
17
org.springframework.boot
18
spring-boot-starter-web
19
20
21
22
org.springframework.boot
23
spring-boot-starter-actuator
24
25
26
org.springframework.boot
27
spring-boot-starter-freemarker
28
29
30
31
com.weibo
32
motan-core
33
0.2.2
34
35
36
37
com.weibo
38
motan-transport-netty
39
0.2.2
40
41
42
43
com.weibo
44
motan-springsupport
45
0.2.1
46
47
48
49
com.weibo
50
motan-registry-zookeeper
51
0.2.1
52
53 54
55
56
com.motan.zookeper
57
motan-zookeper-api
58
1.0-SNAPSHOT
59
compile
60
61
62
View Code

3. 模块依赖关系图

4. 层说明

  • motan-zookeper-api     ——业务逻辑接口
  • motan-zookeper-model  ——实体类
  • motan-zookeper-service  ——数据访问层,业务逻辑层的实现
  • motan-zookeper-web    ——表现层

5. 各模块的结构

5.1  motan-zookeper-api

5.2  motan-zookeper-model

 

5.3 motan-zookeper-service

 

5.3.1.  JpaConfig.java

 

1 package com.motan.zookeper.config; 2  3 import org.springframework.boot.autoconfigure.domain.EntityScan; 4 import org.springframework.context.annotation.Configuration; 5 import org.springframework.data.jpa.repository.config.EnableJpaRepositories; 6  7 @Configuration 8 @EntityScan(basePackages = {"com.motan.zookeper.model"}) 9 @EnableJpaRepositories(basePackages = {"com.motan.zookeper.repository"})10 public class JpaConfig {11 }
View Code

5.3.2.  MotanConfig.java

 

1 package com.motan.zookeper.config; 2  3 import com.weibo.api.motan.config.springsupport.*; 4 import org.springframework.beans.factory.annotation.Value; 5 import org.springframework.context.annotation.Bean; 6 import org.springframework.context.annotation.Configuration; 7  8 @Configuration 9 public class MotanConfig {10 11     @Bean12     public AnnotationBean motanAnnotationBean(@Value("${motan.annotation.package}") String packageName) {13         AnnotationBean motanAnnotationBean = new AnnotationBean();14         motanAnnotationBean.setPackage(packageName);15         return motanAnnotationBean;16     }17 18     @Bean(name = "motan")19     public ProtocolConfigBean protocolConfig() {20         ProtocolConfigBean config = new ProtocolConfigBean();21         config.setDefault(true);22         config.setSerialization("hessian2");23         config.setName("motan");24         config.setMaxContentLength(1548576);25         config.setRequestTimeout(50000000);26 27         return config;28     }29 30     @Bean(name = "registry")31     public RegistryConfigBean registryConfigSit(@Value("${motan.zookeeper.host}") String zookeeperAddress) {32         RegistryConfigBean config = new RegistryConfigBean();33         config.setDefault(true);34         config.setRegProtocol("zookeeper");35         config.setAddress(zookeeperAddress);36         return config;37     }38 39     /**40      * 服务端配置41      */42     @Bean(name = "motanServerBasicConfig")43     public BasicServiceConfigBean baseServiceConfig(@Value("${motan.export.port}") String port) {44         BasicServiceConfigBean config = new BasicServiceConfigBean();45         config.setDefault(true);46         config.setExport("motan:" + port);47         config.setGroup("sinomall");48         config.setAccessLog(false);49         config.setShareChannel(true);50         config.setRequestTimeout(9000000);51         config.setRegistry("registry");52         return config;53     }54 55     /**56      * 客户端配置57      */58     @Bean(name = "motanClientBasicConfig")59     public BasicRefererConfigBean baseRefererConfig() {60         BasicRefererConfigBean config = new BasicRefererConfigBean();61         config.setProtocol("motan");62         config.setGroup("sinomall");63         config.setAccessLog(false);64         config.setRegistry("registry");65         config.setCheck(false);66         config.setRetries(0);67         config.setThrowException(true);68         config.setRequestTimeout(9000);69         config.setDefault(true);70         return config;71     }72 }
View Code

5.3.3.  MotanZookeperServiceApp.java

 

1 package com.motan.zookeper; 2  3 import com.weibo.api.motan.common.MotanConstants; 4 import com.weibo.api.motan.util.MotanSwitcherUtil; 5 import org.springframework.boot.SpringApplication; 6 import org.springframework.boot.autoconfigure.SpringBootApplication; 7  8 @SpringBootApplication 9 public class MotanZookeperServiceApp {10     public static void main(String[] args) {11         SpringApplication.run(MotanZookeperServiceApp.class,args);12         //服务提供方需要开启心跳检测13         MotanSwitcherUtil.setSwitcherValue(MotanConstants.REGISTRY_HEARTBEAT_SWITCHER, true);14         System.out.println("服务端启动");15     }16 }
View Code

5.3.4.  application.properties

 

1 # 数据源配置 2 spring.datasource.url=jdbc:log4jdbc:mysql://127.0.0.1:3306/motan-zookeper?useUnicode=true&characterEncoding=utf-8 3 spring.datasource.username=root 4 spring.datasource.password=root 5 spring.datasource.driver-class-name=net.sf.log4jdbc.DriverSpy 6 # jpa配置 7 spring.jpa.database=mysql 8 spring.jpa.show-sql=true 9 spring.jpa.hibernate.ddl-auto=update10 # sql 日志11 logging.level.jdbc=error12 logging.level.jdbc.sqltiming=info13 # motan配置14 motan.annotation.package=com.motan.zookeper15 motan.export.port=${random.int[5001,9999]}16 motan.zookeeper.host=127.0.0.1:2181
View Code

5.4.  motan-zookeper-web

5.4.1.  MotanConfig.java

1 package com.motan.zookeper.config; 2  3 import com.weibo.api.motan.config.springsupport.*; 4 import org.springframework.beans.factory.annotation.Value; 5 import org.springframework.context.annotation.Bean; 6 import org.springframework.context.annotation.Configuration; 7  8 @Configuration 9 public class MotanConfig {10 11     @Bean12     public AnnotationBean motanAnnotationBean(@Value("${motan.annotation.package}") String packageName) {13         AnnotationBean motanAnnotationBean = new AnnotationBean();14         motanAnnotationBean.setPackage(packageName);15         return motanAnnotationBean;16     }17 18     @Bean(name = "motan")19     public ProtocolConfigBean protocolConfig() {20         ProtocolConfigBean config = new ProtocolConfigBean();21         config.setDefault(true);22         config.setSerialization("hessian2");23         config.setName("motan");24         config.setMaxContentLength(1548576);25         config.setRequestTimeout(50000000);26 27         return config;28     }29 30     @Bean(name = "registry")31     public RegistryConfigBean registryConfigSit(@Value("${motan.zookeeper.host}") String zookeeperAddress) {32         RegistryConfigBean config = new RegistryConfigBean();33         config.setDefault(true);34         config.setRegProtocol("zookeeper");35         config.setAddress(zookeeperAddress);36         return config;37     }38 39     /**40      * 服务端配置41      */42     @Bean(name = "motanServerBasicConfig")43     public BasicServiceConfigBean baseServiceConfig(@Value("${motan.export.port}") String port) {44         BasicServiceConfigBean config = new BasicServiceConfigBean();45         config.setDefault(true);46         config.setExport("motan:" + port);47         config.setGroup("sinomall");48         config.setAccessLog(false);49         config.setShareChannel(true);50         config.setRequestTimeout(9000000);51         config.setRegistry("registry");52         return config;53     }54 55     /**56      * 客户端配置57      */58     @Bean(name = "motanClientBasicConfig")59     public BasicRefererConfigBean baseRefererConfig() {60         BasicRefererConfigBean config = new BasicRefererConfigBean();61         config.setProtocol("motan");62         config.setGroup("sinomall");63         config.setAccessLog(false);64         config.setRegistry("registry");65         config.setCheck(false);66         config.setRetries(0);67         config.setThrowException(true);68         config.setRequestTimeout(9000);69         config.setDefault(true);70         return config;71     }72 }
View Code

5.4.2.  MotanZookeperWebApp

1 package com.motan.zookeper; 2  3 import org.springframework.boot.SpringApplication; 4 import org.springframework.boot.autoconfigure.SpringBootApplication; 5  6 @SpringBootApplication 7 public class MotanZookeperWebApp { 8     public static void main(String[] args) { 9         SpringApplication.run(MotanZookeperWebApp.class,args);10         System.out.println("客户端启动");11     }12 }
View Code

5.4.3.  application.properties

1 server.port=70802 # motan配置3 motan.annotation.package=com.motan.zookeper4 motan.export.port=${random.int[5001,9999]}5 motan.zookeeper.host=127.0.0.1:2181

6. 启动应用

1)     启动本地的zookeper服务

2)     启动MotanZookeperServiceApp

3)     启动MotanZookeperWebApp

转载于:https://www.cnblogs.com/jcjssl/p/9363410.html

你可能感兴趣的文章
QTP解决内嵌IE窗体方法2
查看>>
“王子”的演讲:N828印象
查看>>
判断JS字符串中是否包含某些字符
查看>>
Phalanger---PHP的.NET编译器
查看>>
Scanner----java控制台和文件读取的利器(java 5新增)
查看>>
如何安全设定和检测你的密码安全性?
查看>>
一例HP ADG数据恢复成功(8×73GB SCSI)
查看>>
虚拟化系列-Citrix XenServer 6.1 XenMotion与HA
查看>>
TFS创建团队项目(三)
查看>>
对发展的一点小感想
查看>>
示例化讲解RIP路由更新机制
查看>>
eclipse不能自动编译工程的解决方法
查看>>
Powershell管理系列(九)删除Exchange用户邮箱中多余的电子邮件地址
查看>>
Swt/Jface进度条
查看>>
.NET建议使用的大小写命名原则
查看>>
Git:错误:error:src refspec master does not match any
查看>>
SSIS 数据类型和类型转换
查看>>
Oracle数据库“Specified cast is农田valid”
查看>>
数据层新思路,写数据库无关的数据层 ORM在数据库内做更为合适
查看>>
armv8(aarch64)linux内核中flush_dcache_all函数详细分析【转】
查看>>