File tree Expand file tree Collapse file tree 3 files changed +38
-16
lines changed
protocol-grpc/src/main/scala/com/devsisters/shardcake Expand file tree Collapse file tree 3 files changed +38
-16
lines changed Original file line number Diff line number Diff line change 1
1
package com .devsisters .shardcake
2
2
3
+ import java .util .concurrent .Executor
4
+
3
5
/**
4
6
* The configuration for the gRPC client.
7
+ *
5
8
* @param maxInboundMessageSize the maximum message size allowed to be received by the grpc client
9
+ * @param executor a custom executor to pass to grpc-java when creating gRPC clients and servers
6
10
*/
7
- case class GrpcConfig (maxInboundMessageSize : Int )
11
+ case class GrpcConfig (maxInboundMessageSize : Int , executor : Option [ Executor ] )
8
12
9
13
object GrpcConfig {
10
14
val default : GrpcConfig =
11
- GrpcConfig (maxInboundMessageSize = 32 * 1024 * 1024 )
15
+ GrpcConfig (maxInboundMessageSize = 32 * 1024 * 1024 , None )
12
16
}
Original file line number Diff line number Diff line change @@ -25,13 +25,23 @@ class GrpcPods(
25
25
map.get(pod) match {
26
26
case Some ((channel, _)) => ZIO .succeed((channel, map))
27
27
case None =>
28
- val channel : ZManagedChannel =
29
- ZManagedChannel .apply(
30
- ManagedChannelBuilder
31
- .forAddress(pod.host, pod.port)
32
- .maxInboundMessageSize(config.maxInboundMessageSize)
33
- .usePlaintext()
34
- )
28
+ val builder = {
29
+ config.executor match {
30
+ case Some (executor) =>
31
+ ManagedChannelBuilder
32
+ .forAddress(pod.host, pod.port)
33
+ .executor(executor)
34
+ .maxInboundMessageSize(config.maxInboundMessageSize)
35
+ .usePlaintext()
36
+ case None =>
37
+ ManagedChannelBuilder
38
+ .forAddress(pod.host, pod.port)
39
+ .maxInboundMessageSize(config.maxInboundMessageSize)
40
+ .usePlaintext()
41
+ }
42
+ }
43
+
44
+ val channel = ZManagedChannel (builder)
35
45
// create a fiber that never ends and keeps the connection alive
36
46
for {
37
47
_ <- ZIO .logDebug(s " Opening connection to pod $pod" )
Original file line number Diff line number Diff line change @@ -53,14 +53,22 @@ object GrpcShardingService {
53
53
/**
54
54
* A layer that creates a gRPC server that exposes the Pods API.
55
55
*/
56
- val live : ZLayer [Config with Sharding , Throwable , Unit ] =
57
- ZLayer .scoped[Config with Sharding ] {
56
+ val live : ZLayer [Config with Sharding with GrpcConfig , Throwable , Unit ] =
57
+ ZLayer .scoped[Config with Sharding with GrpcConfig ] {
58
58
for {
59
- config <- ZIO .service[Config ]
60
- sharding <- ZIO .service[Sharding ]
61
- builder = ServerBuilder .forPort(config.shardingPort).addService(ProtoReflectionService .newInstance())
62
- services = ServiceList .add(new GrpcShardingService (sharding, config.sendTimeout) {})
63
- _ <- ScopedServer .fromServiceList(builder, services)
59
+ config <- ZIO .service[Config ]
60
+ grpcConfig <- ZIO .service[GrpcConfig ]
61
+ sharding <- ZIO .service[Sharding ]
62
+ builder = grpcConfig.executor match {
63
+ case Some (executor) =>
64
+ ServerBuilder
65
+ .forPort(config.shardingPort)
66
+ .executor(executor)
67
+ case None =>
68
+ ServerBuilder .forPort(config.shardingPort)
69
+ }
70
+ services = ServiceList .add(new GrpcShardingService (sharding, config.sendTimeout) {})
71
+ _ <- ScopedServer .fromServiceList(builder.addService(ProtoReflectionService .newInstance()), services)
64
72
} yield ()
65
73
}
66
74
}
You can’t perform that action at this time.
0 commit comments