Grpc client with channel whose name is derived from the stub class

22 hours ago 3
ARTICLE AD BOX

In Spring-Grpc, I can configure clients declared as a beans to use named channels:

@Bean MyServiceGrpc.SimpleBlockingStub stub(GrpcChannelFactory channels) { return MyServiceGrpc.newBlockingStub(channels.createChannel("my-service")); } @Bean AnotherServiceGrpc.SimpleBlockingStub stub(GrpcChannelFactory channels) { return AnotherServiceGrpc.newBlockingStub(channels.createChannel("another-service")); }

and then configure those channels in my application properties. For example:

spring.grpc.client.channels.my-service.address=0.0.0.0:9090 spring.grpc.client.channels.another-service.address=0.0.0.0:9091

Alternatively, I can have them created via annotations:

@ImportGrpcClients(target = "my-service", types = MyServiceGrpc.SimpleBlockingStub.class) @ImportGrpcClients(target = "another-service", types = AnotherServiceGrpc.SimpleBlockingStub.class)

I would like to just use this annotation with package scanning, rather than listing all the clients, and have it work out the name of the channel based on the name of the service.

@ImportGrpcClients(basePackages = "mycompany.clients.com")

Is that possible?

Read Entire Article