How to properly communicate between services #3229
-
Hello! I'm new to the library and I'd like to know how to do one task. I have 2 services (running on different instances), lets call them serviceA and serviceB. ServiceA does some basic calculations but heavier ones are redirected to ServiceB. My doubt comes in this moment. What is the best way to redirect this request from ServiceA to ServiceB? Having in mind that the client cannot reach ServiceB for X reasons. So I understand that as ServiceA needs to communicate with ServiceB, ServiceA needs a hyper::Client, but should I create a hyper::Client for each redirection or just create one and use only that instance? I read on the docs that cloning the hyper::Client is very cheap and it keeps the underlaying connection, should this be the way to go? Clone the instance each time I have to communicate with ServiceB? I'm using Tokio to be able to handle many requests simultaneously so many requests could be redirected to ServiceB simultaneously too. Any help would be appreciated! Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yes, if ServiceB is on a separate host or process than ServiceA, you could make use of hyper's client to send requests to it. I would say that unless you know a very specific reason why not to, the best thing to do is to reuse a single client, cloning it. Is there something about the docs that makes it unclear? |
Beta Was this translation helpful? Give feedback.
Yes, if ServiceB is on a separate host or process than ServiceA, you could make use of hyper's client to send requests to it. I would say that unless you know a very specific reason why not to, the best thing to do is to reuse a single client, cloning it.
Is there something about the docs that makes it unclear?