Bind all your gprc endpoints with a simple and magic coRouter

grpc-services are quite simple, focused and performance oriented services.
Instead of calling them with a format that needs complex marshalling / unmarshalling, and making use of a standard http 1.1 connection, grpc has a dedicated (therefore faster) generated code for each type.
This protocol also indexes data fields by number, which permits to shrink the input by many folds
(if you know the order of the keys in the structure, then you don’t need to indicate them in your payload)

grpc work efficiently with naive Netty servers (all you have to do is to call .bindService()).
But the integration is not so smooth when you currently have reactive spring components to integrate with (authentication, libraries, aspects).
When I have discovered coRouters, I was able to understand that one of its purpose was to dynamically declare endpoints based upon spring beans.

Then if you mix these two concepts together (grpc and coRouters), you can build autowired grpc services on spring.
How do you do that ?
Simply by copy / pasting this snippet in your codebase : https://gist.github.com/libetl/a655de480ed4d123e0c10fe557ea4271

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.