armeria

How to call multiple service?


When I use Armeria, I have 3 services:

Service A calls Service B and Service C.

Should I call B and C's blocking stub in A's blockingTaskExecutor or some other better way?


Solution

  • Let me assume that you're asking about gRPC. In asynchronous frameworks like Armeria, it is recommended to use a non-blocking stub to make a call, so that there are no blocking calls and thus the calls to other services (Service B and C in your case) are all done in an event loop thread. This yields potentially higher performance thanks to less amount of context switching and more robustness when the other services are not responsive enough.

    You can use the default stub generated by gRPC-Java to do that, but the end result may be more complex than necessary, so I'd recommend using a third party stub generators such as reactive-grpc, which provides the integration with RxJava and Project Reactor.

    If you are using Kotlin, you might want to give grpc-kotlin a try, but please keep in mind that it's at the early stage.