Skip to content

Commit 3f99bc4

Browse files
author
YunaiV
committed
增加 Motan 入门
1 parent ac2ee41 commit 3f99bc4

File tree

15 files changed

+123
-93
lines changed

15 files changed

+123
-93
lines changed

lab-63/lab-63-motan-xml-demo/lab-62-sofarpc-xml-demo-user-rpc-service-consumer/pom.xml

-45
This file was deleted.

lab-63/lab-63-motan-xml-demo/lab-62-sofarpc-xml-demo-user-rpc-service-consumer/src/main/resources/application.yaml

-5
This file was deleted.

lab-63/lab-63-motan-xml-demo/lab-62-sofarpc-xml-demo-user-rpc-service-consumer/src/main/resources/sofarpc.xml

-16
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>lab-63-motan-xml-demo</artifactId>
7+
<groupId>cn.iocoder.springboot.labs</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>lab-63-motan-xml-demo-user-rpc-service-consumer</artifactId>
13+
14+
<properties>
15+
<maven.compiler.target>1.8</maven.compiler.target>
16+
<maven.compiler.source>1.8</maven.compiler.source>
17+
<spring.boot.version>2.2.4.RELEASE</spring.boot.version>
18+
<moton.version>1.1.8</moton.version>
19+
</properties>
20+
21+
<dependencyManagement>
22+
<dependencies>
23+
<dependency>
24+
<groupId>org.springframework.boot</groupId>
25+
<artifactId>spring-boot-starter-parent</artifactId>
26+
<version>${spring.boot.version}</version>
27+
<type>pom</type>
28+
<scope>import</scope>
29+
</dependency>
30+
</dependencies>
31+
</dependencyManagement>
32+
33+
<dependencies>
34+
<!-- 引入定义的 Motan API 接口 -->
35+
<dependency>
36+
<groupId>cn.iocoder.springboot.labs</groupId>
37+
<artifactId>lab-63-motan-xml-demo-user-rpc-service-api</artifactId>
38+
<version>1.0-SNAPSHOT</version>
39+
</dependency>
40+
41+
<!-- 引入 SpringMVC 的 Spring Boot 依赖 -->
42+
<dependency>
43+
<groupId>org.springframework.boot</groupId>
44+
<artifactId>spring-boot-starter-web</artifactId>
45+
</dependency>
46+
47+
<!-- 引入 Motan 相关依赖 -->
48+
<dependency>
49+
<groupId>com.weibo</groupId>
50+
<artifactId>motan-core</artifactId>
51+
<version>${moton.version}</version>
52+
</dependency>
53+
<dependency>
54+
<groupId>com.weibo</groupId>
55+
<artifactId>motan-transport-netty4</artifactId>
56+
<version>${moton.version}</version>
57+
</dependency>
58+
<dependency>
59+
<groupId>com.weibo</groupId>
60+
<artifactId>motan-registry-zookeeper</artifactId>
61+
<version>${moton.version}</version>
62+
</dependency>
63+
<dependency>
64+
<groupId>com.weibo</groupId>
65+
<artifactId>motan-springsupport</artifactId>
66+
<version>${moton.version}</version>
67+
</dependency>
68+
69+
</dependencies>
70+
71+
</project>
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import org.springframework.context.annotation.ImportResource;
66

77
@SpringBootApplication
8-
@ImportResource("classpath:sofarpc.xml")
8+
@ImportResource("classpath:motan.xml")
99
public class ConsumerApplication {
1010

1111
public static void main(String[] args) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
spring:
2+
application:
3+
name: user-service-consumer # 应用名
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<beans xmlns="http://www.springframework.org/schema/beans"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns:motan="http://api.weibo.com/schema/motan"
4+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
5+
http://api.weibo.com/schema/motan http://api.weibo.com/schema/motan.xsd">
6+
7+
<!-- 使用 Zookeeper 作为注册中心 -->
8+
<motan:registry name="registry" regProtocol="zookeeper" address="127.0.0.1:2181" connectTimeout="2000"/>
9+
10+
<!-- motan2 with hessian serialization -->
11+
<motan:protocol id="motan2" name="motan2" haStrategy="failover"
12+
loadbalance="roundrobin" maxClientConnection="10" minClientConnection="2"/>
13+
14+
<motan:referer id="userRpcService" interface="cn.iocoder.springboot.lab63.rpc.api.UserRpcService" />
15+
16+
</beans>

lab-63/lab-63-motan-xml-demo/lab-63-motan-xml-demo-user-rpc-service-provider/pom.xml

+3-9
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
</dependencyManagement>
3232

3333
<dependencies>
34-
<!-- 引入定义的 SOFARPC API 接口 -->
34+
<!-- 引入定义的 Motan API 接口 -->
3535
<dependency>
3636
<groupId>cn.iocoder.springboot.labs</groupId>
3737
<artifactId>lab-63-motan-xml-demo-user-rpc-service-api</artifactId>
@@ -44,15 +44,15 @@
4444
<artifactId>spring-boot-starter</artifactId>
4545
</dependency>
4646

47-
<!-- 实现对 SOFARPC 的自动化配置 -->
47+
<!-- 引入 Motan 相关依赖 -->
4848
<dependency>
4949
<groupId>com.weibo</groupId>
5050
<artifactId>motan-core</artifactId>
5151
<version>${moton.version}</version>
5252
</dependency>
5353
<dependency>
5454
<groupId>com.weibo</groupId>
55-
<artifactId>motan-transport-netty</artifactId>
55+
<artifactId>motan-transport-netty4</artifactId>
5656
<version>${moton.version}</version>
5757
</dependency>
5858
<dependency>
@@ -66,12 +66,6 @@
6666
<version>${moton.version}</version>
6767
</dependency>
6868

69-
<!-- 使用 Zookeeper 作为注册中心 -->
70-
<!-- <dependency>-->
71-
<!-- <groupId>org.apache.curator</groupId>-->
72-
<!-- <artifactId>curator-framework</artifactId>-->
73-
<!-- </dependency>-->
74-
7569
</dependencies>
7670

7771
</project>
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
package cn.iocoder.springboot.lab63.rpc;
22

3+
import com.weibo.api.motan.common.MotanConstants;
4+
import com.weibo.api.motan.util.MotanSwitcherUtil;
35
import org.springframework.boot.SpringApplication;
46
import org.springframework.boot.autoconfigure.SpringBootApplication;
57
import org.springframework.context.annotation.ImportResource;
68

79
@SpringBootApplication
8-
@ImportResource("classpath:sofarpc.xml")
10+
@ImportResource("classpath:motan.xml")
911
public class ProviderApplication {
1012

1113
public static void main(String[] args) {
14+
1215
// 启动 Spring Boot 应用
1316
SpringApplication.run(ProviderApplication.class, args);
17+
MotanSwitcherUtil.setSwitcherValue(MotanConstants.REGISTRY_HEARTBEAT_SWITCHER, true);
1418
}
1519

1620
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
spring:
22
application:
33
name: user-service-provider # 应用名
4-
5-
com.alipay.sofa.rpc.registry.address: zookeeper://127.0.0.1:2181 # SOFA RPC 注册中心
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<beans xmlns="http://www.springframework.org/schema/beans"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns:motan="http://api.weibo.com/schema/motan"
4+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
5+
http://api.weibo.com/schema/motan http://api.weibo.com/schema/motan.xsd">
6+
7+
<!-- 使用 Zookeeper 作为注册中心 -->
8+
<motan:registry name="registry" regProtocol="zookeeper" address="127.0.0.1:2181" connectTimeout="2000"/>
9+
10+
<!-- <motan:service ref="userRpcServiceImpl" interface="cn.iocoder.springboot.lab63.rpc.service.UserRpcServiceImpl"-->
11+
<!-- export="motan2:8001">-->
12+
<!-- </motan:service>-->
13+
14+
<!-- 协议配置。为防止多个业务配置冲突,推荐使用id表示具体协议。-->
15+
<!-- motan2 with hessian2 serialization -->
16+
<motan:protocol id="motan2" default="true" name="motan2"
17+
maxServerConnection="80000" maxContentLength="1048576"
18+
maxWorkerThread="800" minWorkerThread="20" />
19+
20+
<motan:service ref="userRpcServiceImpl" interface="cn.iocoder.springboot.lab63.rpc.api.UserRpcService" export="motan2:8001" />
21+
22+
</beans>

lab-63/lab-63-motan-xml-demo/lab-63-motan-xml-demo-user-rpc-service-provider/src/main/resources/sofarpc.xml

-12
This file was deleted.

lab-63/lab-63-motan-xml-demo/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<modules>
1515
<module>lab-63-motan-xml-demo-user-rpc-service-api</module>
1616
<module>lab-63-motan-xml-demo-user-rpc-service-provider</module>
17-
<!-- <module>lab-63-sofarpc-xml-demo-user-rpc-service-consumer</module>-->
17+
<module>lab-63-motan-xml-demo-user-rpc-service-consumer</module>
1818
</modules>
1919

2020
</project>

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
<!-- <module>lab-59</module>-->
7373
<!-- <module>lab-60</module>-->
7474
<!-- <module>lab-61</module>-->
75-
<module>lab-62</module>
75+
<!-- <module>lab-62</module>-->
7676
<module>lab-63</module>
7777

7878
<!-- Spring Cloud 示例 -->

0 commit comments

Comments
 (0)