-
Notifications
You must be signed in to change notification settings - Fork 997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use several services using the Tower service approach #309
Comments
@robertohuertasm do you need to make a request for the token on each request or can you have some sort of background task that say updates a mutex? If you can go with the later version (which I have seen is more) common you can use the interceptors. Otherwise, we have an issue #269 for exposing a way to instead of serving directly from the router to expose its generated service that you can then call directly in your own hyper implementation. |
@LucioFranco this token is the one authorizing the caller to access to the grpc api so it has to be validated prior to accessing the resource. The authorization server is third party server, so I have to make a request there. I guess I could add this logic to each endpoint in the services but I was wondering if there was a simple way to add a middleware wrapping all these calls. So, according to your answer, should I assume that by using the Tower service approach, for the moment, I should manage the routing to the different services myself? Is that right? At least until #269 story gets merged. |
I think here then adding it to each handler in the async fn actually might be easier to understand and reason about than writing some complex service stack? In theory you could just add a If you want to go with the tower method then you will have to do the routing by yourself for now. You can peek in the |
Yes, I took a look at it yesterday to understand how the Router was working. Thanks @LucioFranco for your help and your awesome work! 👍 I think I have enough options for the moment to cover my use case. |
@robertohuertasm great, feel free to hop on the discord and ping me if you have any further questions! |
btw, which discord channel are you in? I was looking for it but couldn't find it. Is it the Rustlang discord or a specific one? |
@robertohuertasm we have a tokio based one here https://discord.gg/tokio and there is a #tonic channel |
That's awesome! Thanks again @LucioFranco! |
I was using
add_service
to do multiplexing of several services but I needed to implement some sort of middleware in order to validate a token. I went first with theinterceptor
approach but didn't work for me as they don't seem to supportasync
and I need to occasionally make a request to a third party server to make a validation.Then I went for the
warp/tonic/tower
example in order to get access to therequest
and do some async stuff before calling theservice
. But then, a couple of questions arose:add_service
in such scenario? i.e. if I needed to addserver2
how would I proceed?async
inside the closure passed as argument totower::service_fn
. If I use it I get compiler errors when I await the result of the call (async { server.call(req).await }
=> captured variable cannot escapeFnMut
closure body). I can overcome this issue by not using async/await and using just futures chain methods (e.g.and_then
), so it's not a blocker for the moment. Just curious about whether there are other ways to solve this.I suspect this question is not really related to Tonic but to how it relates to Hyper and Tower. I'm starting to get dirty with all these libs so apologies if the question is naive. 😉
The text was updated successfully, but these errors were encountered: