Skip to content

Commit 5bf94f7

Browse files
authoredOct 22, 2020
change grpc client transaction start requirement and add grpc demo README.md (dromara#232)
* add grpc demo * demo fix * tars filter and demo fix * add hmily-grpc and hmily-grpc-demo * polish grpc client and add license * mod grpc client transaction start requirement and add grpc demo README.md
1 parent 4550bd2 commit 5bf94f7

File tree

5 files changed

+45
-11
lines changed

5 files changed

+45
-11
lines changed
 

‎hmily-demo/hmily-demo-grpc/README.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# 环境准备
2+
- JDK 1.8+
3+
- Maven 3.2.x
4+
- Git
5+
6+
# 代码拉取
7+
```
8+
> git clone https://github.com/dromara/hmily.git
9+
10+
> cd hmily
11+
12+
> mvn -DskipTests clean install -U
13+
```
14+
15+
# 执行demo 模块的sql语句。
16+
[sql语句] (https://github.com/dromara/hmily/blob/master/hmily-demo/sql/hmily-demo.sql)
17+
18+
# 使用你的工具 idea 打开项目,找到hmily-demo-grpc项目。
19+
## 修改项目配置(hmily-demo-grpc-account为列子)
20+
- application.yml 下修改业务数据库
21+
```
22+
spring:
23+
datasource:
24+
driver-class-name: com.mysql.jdbc.Driver
25+
url: jdbc:mysql://改成你的ip+端口/hmily_account?useUnicode=true&characterEncoding=utf8
26+
username: #改成你的用户名
27+
password: #改成你的密码
28+
```
29+
- 修改 hmily.yml,这里使用mysql来存储
30+
```
31+
repository:
32+
database:
33+
driverClassName: com.mysql.jdbc.Driver
34+
url : jdbc:mysql://改成你的ip+端口/hmily?useUnicode=true&characterEncoding=utf8
35+
username: root #改成你的用户名
36+
password: #改成你的密码
37+
```
38+
39+
- run TarsHmilyAccountApplication.java
40+
41+
## 启动hmily-demo-grpc-inventory 参考上述。
42+
43+
## 启动hmily-demo-grpc-order 参考上述。
44+
45+
访问:http://127.0.0.1:28087/swagger-ui.html。

‎hmily-demo/hmily-demo-grpc/hmily-demo-grpc-common/src/main/java/org/dromara/hmily/demo/grpc/account/service/AccountServiceGrpc.java

-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import io.grpc.MethodDescriptor;
44
import io.grpc.stub.ClientCalls;
55
import io.grpc.stub.ServerCalls;
6-
import org.dromara.hmily.annotation.Hmily;
76

87
import static io.grpc.stub.ClientCalls.asyncUnaryCall;
98
import static io.grpc.stub.ClientCalls.asyncServerStreamingCall;
@@ -136,7 +135,6 @@ protected AccountServiceBlockingStub build(io.grpc.Channel channel,
136135

137136
/**
138137
*/
139-
@Hmily
140138
public org.dromara.hmily.demo.grpc.account.service.AccountResponse payment(org.dromara.hmily.demo.grpc.account.service.AccountRequest request) {
141139
return ClientCalls.blockingUnaryCall(
142140
getChannel(), METHOD_PAYMENT, getCallOptions(), request);

‎hmily-demo/hmily-demo-grpc/hmily-demo-grpc-common/src/main/java/org/dromara/hmily/demo/grpc/inventory/service/InventoryServiceGrpc.java

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package org.dromara.hmily.demo.grpc.inventory.service;
22

3-
import org.dromara.hmily.annotation.Hmily;
4-
53
import static io.grpc.stub.ClientCalls.asyncUnaryCall;
64
import static io.grpc.stub.ClientCalls.blockingUnaryCall;
75
import static io.grpc.stub.ClientCalls.futureUnaryCall;
@@ -125,7 +123,6 @@ protected InventoryServiceBlockingStub build(io.grpc.Channel channel,
125123

126124
/**
127125
*/
128-
@Hmily
129126
public org.dromara.hmily.demo.grpc.inventory.service.InventoryResponse decrease(org.dromara.hmily.demo.grpc.inventory.service.InventoryRequest request) {
130127
return blockingUnaryCall(
131128
getChannel(), METHOD_DECREASE, getCallOptions(), request);

‎hmily-demo/hmily-demo-grpc/hmily-demo-grpc-order/src/main/java/org/dromara/hmily/demo/grpc/order/grpc/AccountClient.java

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import io.grpc.ManagedChannel;
44
import io.grpc.ManagedChannelBuilder;
5-
import org.dromara.hmily.core.holder.SingletonHolder;
65
import org.dromara.hmily.demo.grpc.account.service.AccountRequest;
76
import org.dromara.hmily.demo.grpc.account.service.AccountResponse;
87
import org.dromara.hmily.demo.grpc.account.service.AccountServiceGrpc;

‎hmily-rpc/hmily-grpc/src/main/java/org/dromara/hmily/grpc/filter/GrpcHmilyTransactionFilter.java

-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import io.grpc.Metadata;
3131
import io.grpc.Status;
3232
import io.grpc.ForwardingClientCallListener;
33-
import org.dromara.hmily.annotation.Hmily;
3433
import org.dromara.hmily.common.enums.HmilyActionEnum;
3534
import org.dromara.hmily.common.enums.HmilyRoleEnum;
3635
import org.dromara.hmily.common.exception.HmilyRuntimeException;
@@ -74,10 +73,6 @@ public <R, P> ClientCall<R, P> interceptCall(final MethodDescriptor<R, P> method
7473
}
7574
}
7675
if (method != null) {
77-
Hmily hmily = method.getAnnotation(Hmily.class);
78-
if (Objects.isNull(hmily)) {
79-
return channel.newCall(methodDescriptor, callOptions);
80-
}
8176
Class<?>[] arg = method.getParameterTypes();
8277
Long participantId = context.getParticipantId();
8378
HmilyParticipant hmilyParticipant = buildParticipant(context, methodName, clazz, arg);

0 commit comments

Comments
 (0)