GrpcConfig.java
15.5 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
package com.infoloop.tianting.config;
import com.infoloop.rpc.meizhongyiheservice.MeiZhongYiHeServiceRpcGrpc;
import com.infoloop.tianting.COperatorServiceProtoRpcGrpc;
import com.infoloop.tianting.CategoriesServiceProtoRpcGrpc;
import com.infoloop.tianting.SkuServiceProtoRpcGrpc;
import com.infoloop.tianting.WOperatorServiceProtoRpcGrpc;
import com.infoloop.tianting.clientcustomerorderservice.ClientCustomerOrderServiceRpcGrpc;
import com.infoloop.tianting.clientcustomerservice.ClientCustomerServiceRpcGrpc;
import com.infoloop.tianting.clientinventoryservice.TiantingClientInventoryServiceRpcGrpc;
import com.infoloop.tianting.clientresourcetagservice.ClientResourceTagServiceRpcGrpc;
import com.infoloop.tianting.deliveryruleservice.TiantingDeliveryRuleServiceRpcGrpc;
import com.infoloop.tianting.enterpriseresourcetagservice.EnterpriseResourceTagServiceRpcGrpc;
import com.infoloop.tianting.menuservice.MenuServiceRpcGrpc;
import com.infoloop.tianting.setmealscheduleservice.SetMealScheduleServiceRpcGrpc;
import io.grpc.ClientInterceptor;
import io.grpc.ManagedChannel;
import io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.concurrent.TimeUnit;
import static com.infoloop.tianting.constant.ConfigConstants.CATEGORY_SERVICE_CHANNEL;
import static com.infoloop.tianting.constant.ConfigConstants.CATEGORY_SERVICE_RPC_PORT;
import static com.infoloop.tianting.constant.ConfigConstants.CATEGORY_SERVICE_RPC_URL;
import static com.infoloop.tianting.constant.ConfigConstants.CLIENT_CUSTOMER_SERVICE_CHANNEL;
import static com.infoloop.tianting.constant.ConfigConstants.CLIENT_CUSTOMER_SERVICE_RPC_PORT;
import static com.infoloop.tianting.constant.ConfigConstants.CLIENT_CUSTOMER_SERVICE_RPC_URL;
import static com.infoloop.tianting.constant.ConfigConstants.CLIENT_INVENTORY_SERVICE_CHANNEL;
import static com.infoloop.tianting.constant.ConfigConstants.CLIENT_INVENTORY_SERVICE_RPC_PORT;
import static com.infoloop.tianting.constant.ConfigConstants.CLIENT_INVENTORY_SERVICE_RPC_URL;
import static com.infoloop.tianting.constant.ConfigConstants.CLIENT_RESOURCE_SERVICE_CHANNEL;
import static com.infoloop.tianting.constant.ConfigConstants.CLIENT_RESOURCE_SERVICE_RPC_PORT;
import static com.infoloop.tianting.constant.ConfigConstants.CLIENT_RESOURCE_SERVICE_RPC_URL;
import static com.infoloop.tianting.constant.ConfigConstants.DELIVERY_SERVICE_CHANNEL;
import static com.infoloop.tianting.constant.ConfigConstants.DELIVERY_SERVICE_RPC_PORT;
import static com.infoloop.tianting.constant.ConfigConstants.DELIVERY_SERVICE_RPC_URL;
import static com.infoloop.tianting.constant.ConfigConstants.ENTERPRISE_RESOURCE_SERVICE_CHANNEL;
import static com.infoloop.tianting.constant.ConfigConstants.ENTERPRISE_RESOURCE_SERVICE_RPC_PORT;
import static com.infoloop.tianting.constant.ConfigConstants.ENTERPRISE_RESOURCE_SERVICE_RPC_URL;
import static com.infoloop.tianting.constant.ConfigConstants.MEAL_SERVICE_CHANNEL;
import static com.infoloop.tianting.constant.ConfigConstants.MEAL_SERVICE_RPC_PORT;
import static com.infoloop.tianting.constant.ConfigConstants.MEAL_SERVICE_RPC_URL;
import static com.infoloop.tianting.constant.ConfigConstants.MEIZHONGYIHE_SERVICE_CHANNEL;
import static com.infoloop.tianting.constant.ConfigConstants.MEIZHONGYIHE_SERVICE_RPC_PORT;
import static com.infoloop.tianting.constant.ConfigConstants.MEIZHONGYIHE_SERVICE_RPC_URL;
import static com.infoloop.tianting.constant.ConfigConstants.MENU_SERVICE_CHANNEL;
import static com.infoloop.tianting.constant.ConfigConstants.MENU_SERVICE_RPC_PORT;
import static com.infoloop.tianting.constant.ConfigConstants.MENU_SERVICE_RPC_URL;
import static com.infoloop.tianting.constant.ConfigConstants.OPERATOR_SERVICE_CHANNEL;
import static com.infoloop.tianting.constant.ConfigConstants.OPERATOR_SERVICE_RPC_PORT;
import static com.infoloop.tianting.constant.ConfigConstants.OPERATOR_SERVICE_RPC_URL;
import static com.infoloop.tianting.constant.ConfigConstants.ORDER_SERVICE_CHANNEL;
import static com.infoloop.tianting.constant.ConfigConstants.ORDER_SERVICE_RPC_PORT;
import static com.infoloop.tianting.constant.ConfigConstants.ORDER_SERVICE_RPC_URL;
import static com.infoloop.tianting.constant.ConfigConstants.SKU_SERVICE_CHANNEL;
import static com.infoloop.tianting.constant.ConfigConstants.SKU_SERVICE_RPC_PORT;
import static com.infoloop.tianting.constant.ConfigConstants.SKU_SERVICE_RPC_URL;
import static com.infoloop.tianting.constant.ConfigConstants.WOPERATOR_SERVICE_CHANNEL;
import static com.infoloop.tianting.constant.ConfigConstants.WOPERATOR_SERVICE_RPC_PORT;
import static com.infoloop.tianting.constant.ConfigConstants.WOPERATOR_SERVICE_RPC_URL;
@Configuration
public class GrpcConfig {
private static final int DEFAULT_TIMEOUT_DAYS = 7;
@Bean(ORDER_SERVICE_CHANNEL)
public ManagedChannel orderServiceChannel(@Value(ORDER_SERVICE_RPC_URL) final String url,
@Value(ORDER_SERVICE_RPC_PORT) final int port,
@Autowired final ClientInterceptor clientInterceptor) {
return NettyChannelBuilder.forAddress(url, port)
.idleTimeout(DEFAULT_TIMEOUT_DAYS, TimeUnit.DAYS)
.intercept(clientInterceptor)
.usePlaintext()
.maxInboundMessageSize(Integer.MAX_VALUE)
.build();
}
@Bean
public ClientCustomerOrderServiceRpcGrpc.ClientCustomerOrderServiceRpcBlockingStub orderServiceRpcBlockingStub(@Autowired @Qualifier(ORDER_SERVICE_CHANNEL) final ManagedChannel channel) {
return ClientCustomerOrderServiceRpcGrpc.newBlockingStub(channel);
}
@Bean(MENU_SERVICE_CHANNEL)
public ManagedChannel menuServiceChannel(@Value(MENU_SERVICE_RPC_URL) final String url,
@Value(MENU_SERVICE_RPC_PORT) final int port,
@Autowired final ClientInterceptor clientInterceptor) {
return NettyChannelBuilder.forAddress(url, port)
.idleTimeout(DEFAULT_TIMEOUT_DAYS, TimeUnit.DAYS)
.intercept(clientInterceptor)
.usePlaintext()
.maxInboundMessageSize(Integer.MAX_VALUE)
.build();
}
@Bean
public MenuServiceRpcGrpc.MenuServiceRpcBlockingStub menuServiceRpcBlockingStub(@Autowired @Qualifier(MENU_SERVICE_CHANNEL) final ManagedChannel channel) {
return MenuServiceRpcGrpc.newBlockingStub(channel);
}
@Bean(SKU_SERVICE_CHANNEL)
public ManagedChannel skuServiceChannel(@Value(SKU_SERVICE_RPC_URL) final String url,
@Value(SKU_SERVICE_RPC_PORT) final int port,
@Autowired final ClientInterceptor clientInterceptor) {
return NettyChannelBuilder.forAddress(url, port)
.idleTimeout(DEFAULT_TIMEOUT_DAYS, TimeUnit.DAYS)
.intercept(clientInterceptor)
.usePlaintext()
.maxInboundMessageSize(Integer.MAX_VALUE)
.build();
}
@Bean
public SkuServiceProtoRpcGrpc.SkuServiceProtoRpcBlockingStub skuServiceRpcBlockingStub(@Autowired @Qualifier(SKU_SERVICE_CHANNEL) final ManagedChannel channel) {
return SkuServiceProtoRpcGrpc.newBlockingStub(channel);
}
@Bean(CATEGORY_SERVICE_CHANNEL)
public ManagedChannel categoryServiceChannel(@Value(CATEGORY_SERVICE_RPC_URL) final String url,
@Value(CATEGORY_SERVICE_RPC_PORT) final int port,
@Autowired final ClientInterceptor clientInterceptor) {
return NettyChannelBuilder.forAddress(url, port)
.idleTimeout(DEFAULT_TIMEOUT_DAYS, TimeUnit.DAYS)
.intercept(clientInterceptor)
.usePlaintext()
.maxInboundMessageSize(Integer.MAX_VALUE)
.build();
}
@Bean
public CategoriesServiceProtoRpcGrpc.CategoriesServiceProtoRpcBlockingStub categoryServiceRpcBlockingStub(@Autowired @Qualifier(CATEGORY_SERVICE_CHANNEL) final ManagedChannel channel) {
return CategoriesServiceProtoRpcGrpc.newBlockingStub(channel);
}
@Bean(CLIENT_CUSTOMER_SERVICE_CHANNEL)
public ManagedChannel clientCustomerServiceChannel(@Value(CLIENT_CUSTOMER_SERVICE_RPC_URL) final String url,
@Value(CLIENT_CUSTOMER_SERVICE_RPC_PORT) final int port,
@Autowired final ClientInterceptor clientInterceptor) {
return NettyChannelBuilder.forAddress(url, port)
.idleTimeout(DEFAULT_TIMEOUT_DAYS, TimeUnit.DAYS)
.intercept(clientInterceptor)
.usePlaintext()
.maxInboundMessageSize(Integer.MAX_VALUE)
.build();
}
@Bean
public ClientCustomerServiceRpcGrpc.ClientCustomerServiceRpcBlockingStub customerServiceRpcBlockingStub(@Autowired @Qualifier(CLIENT_CUSTOMER_SERVICE_CHANNEL) final ManagedChannel channel) {
return ClientCustomerServiceRpcGrpc.newBlockingStub(channel);
}
@Bean(CLIENT_INVENTORY_SERVICE_CHANNEL)
public ManagedChannel clientInventoryServiceChannel(@Value(CLIENT_INVENTORY_SERVICE_RPC_URL) final String url,
@Value(CLIENT_INVENTORY_SERVICE_RPC_PORT) final int port,
@Autowired final ClientInterceptor clientInterceptor) {
return NettyChannelBuilder.forAddress(url, port)
.idleTimeout(DEFAULT_TIMEOUT_DAYS, TimeUnit.DAYS)
.intercept(clientInterceptor)
.usePlaintext()
.maxInboundMessageSize(Integer.MAX_VALUE)
.build();
}
@Bean
public TiantingClientInventoryServiceRpcGrpc.TiantingClientInventoryServiceRpcBlockingStub inventoryServiceRpcBlockingStub(@Autowired @Qualifier(CLIENT_INVENTORY_SERVICE_CHANNEL) final ManagedChannel channel) {
return TiantingClientInventoryServiceRpcGrpc.newBlockingStub(channel);
}
@Bean(MEAL_SERVICE_CHANNEL)
public ManagedChannel mealServiceChannel(@Value(MEAL_SERVICE_RPC_URL) final String url,
@Value(MEAL_SERVICE_RPC_PORT) final int port,
@Autowired final ClientInterceptor clientInterceptor) {
return NettyChannelBuilder.forAddress(url, port)
.idleTimeout(DEFAULT_TIMEOUT_DAYS, TimeUnit.DAYS)
.intercept(clientInterceptor)
.usePlaintext()
.maxInboundMessageSize(Integer.MAX_VALUE)
.build();
}
@Bean
public SetMealScheduleServiceRpcGrpc.SetMealScheduleServiceRpcBlockingStub mealServiceRpcBlockingStub(@Autowired @Qualifier(MEAL_SERVICE_CHANNEL) final ManagedChannel channel) {
return SetMealScheduleServiceRpcGrpc.newBlockingStub(channel);
}
@Bean(DELIVERY_SERVICE_CHANNEL)
public ManagedChannel deliveryServiceChannel(@Value(DELIVERY_SERVICE_RPC_URL) final String url,
@Value(DELIVERY_SERVICE_RPC_PORT) final int port,
@Autowired final ClientInterceptor clientInterceptor) {
return NettyChannelBuilder.forAddress(url, port)
.idleTimeout(DEFAULT_TIMEOUT_DAYS, TimeUnit.DAYS)
.intercept(clientInterceptor)
.usePlaintext()
.maxInboundMessageSize(Integer.MAX_VALUE)
.build();
}
@Bean
public TiantingDeliveryRuleServiceRpcGrpc.TiantingDeliveryRuleServiceRpcBlockingStub deliveryServiceRpcBlockingStub(@Autowired @Qualifier(DELIVERY_SERVICE_CHANNEL) final ManagedChannel channel) {
return TiantingDeliveryRuleServiceRpcGrpc.newBlockingStub(channel);
}
@Bean(OPERATOR_SERVICE_CHANNEL)
public ManagedChannel operatorServiceChannel(@Value(OPERATOR_SERVICE_RPC_URL) final String url,
@Value(OPERATOR_SERVICE_RPC_PORT) final int port,
@Autowired final ClientInterceptor clientInterceptor) {
return NettyChannelBuilder.forAddress(url, port)
.idleTimeout(DEFAULT_TIMEOUT_DAYS, TimeUnit.DAYS)
.intercept(clientInterceptor)
.usePlaintext()
.maxInboundMessageSize(Integer.MAX_VALUE)
.build();
}
@Bean
public COperatorServiceProtoRpcGrpc.COperatorServiceProtoRpcBlockingStub operatorServiceRpcBlockingStub(@Autowired @Qualifier(OPERATOR_SERVICE_CHANNEL) final ManagedChannel channel) {
return COperatorServiceProtoRpcGrpc.newBlockingStub(channel);
}
@Bean(WOPERATOR_SERVICE_CHANNEL)
public ManagedChannel woperatorServiceChannel(@Value(WOPERATOR_SERVICE_RPC_URL) final String url,
@Value(WOPERATOR_SERVICE_RPC_PORT) final int port,
@Autowired final ClientInterceptor clientInterceptor) {
return NettyChannelBuilder.forAddress(url, port)
.idleTimeout(DEFAULT_TIMEOUT_DAYS, TimeUnit.DAYS)
.intercept(clientInterceptor)
.usePlaintext()
.maxInboundMessageSize(Integer.MAX_VALUE)
.build();
}
@Bean
public WOperatorServiceProtoRpcGrpc.WOperatorServiceProtoRpcBlockingStub woperatorServiceRpcBlockingStub(@Autowired @Qualifier(WOPERATOR_SERVICE_CHANNEL) final ManagedChannel channel) {
return WOperatorServiceProtoRpcGrpc.newBlockingStub(channel);
}
@Bean(ENTERPRISE_RESOURCE_SERVICE_CHANNEL)
public ManagedChannel enterpriseResourceServiceChannel(@Value(ENTERPRISE_RESOURCE_SERVICE_RPC_URL) final String url,
@Value(ENTERPRISE_RESOURCE_SERVICE_RPC_PORT) final int port,
@Autowired final ClientInterceptor clientInterceptor) {
return NettyChannelBuilder.forAddress(url, port)
.idleTimeout(DEFAULT_TIMEOUT_DAYS, TimeUnit.DAYS)
.intercept(clientInterceptor)
.usePlaintext()
.maxInboundMessageSize(Integer.MAX_VALUE)
.build();
}
@Bean
public EnterpriseResourceTagServiceRpcGrpc.EnterpriseResourceTagServiceRpcBlockingStub enterpriseResourceRpcBlockingStub(@Autowired @Qualifier(ENTERPRISE_RESOURCE_SERVICE_CHANNEL) final ManagedChannel channel) {
return EnterpriseResourceTagServiceRpcGrpc.newBlockingStub(channel);
}
@Bean(MEIZHONGYIHE_SERVICE_CHANNEL)
public ManagedChannel meiZhongYiHeServiceChannel(@Value(MEIZHONGYIHE_SERVICE_RPC_URL) final String url,
@Value(MEIZHONGYIHE_SERVICE_RPC_PORT) final int port,
@Autowired final ClientInterceptor clientInterceptor) {
return NettyChannelBuilder.forAddress(url, port)
.idleTimeout(DEFAULT_TIMEOUT_DAYS, TimeUnit.DAYS)
.intercept(clientInterceptor)
.usePlaintext()
.maxInboundMessageSize(Integer.MAX_VALUE)
.build();
}
@Bean
public MeiZhongYiHeServiceRpcGrpc.MeiZhongYiHeServiceRpcBlockingStub meiZhongYiHeServiceRpcBlockingStub(@Autowired @Qualifier(MEIZHONGYIHE_SERVICE_CHANNEL) final ManagedChannel channel) {
return MeiZhongYiHeServiceRpcGrpc.newBlockingStub(channel);
}
@Bean(CLIENT_RESOURCE_SERVICE_CHANNEL)
public ManagedChannel clientResourceServiceChannel(@Value(CLIENT_RESOURCE_SERVICE_RPC_URL) final String url,
@Value(CLIENT_RESOURCE_SERVICE_RPC_PORT) final int port,
@Autowired final ClientInterceptor clientInterceptor) {
return NettyChannelBuilder.forAddress(url, port)
.idleTimeout(DEFAULT_TIMEOUT_DAYS, TimeUnit.DAYS)
.intercept(clientInterceptor)
.usePlaintext()
.maxInboundMessageSize(Integer.MAX_VALUE)
.build();
}
@Bean
public ClientResourceTagServiceRpcGrpc.ClientResourceTagServiceRpcBlockingStub clientResourceTagServiceRpcBlockingStub(@Autowired @Qualifier(CLIENT_RESOURCE_SERVICE_CHANNEL) final ManagedChannel channel) {
return ClientResourceTagServiceRpcGrpc.newBlockingStub(channel);
}
}