You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TLDR: I would like to have a way to add a service not implementing NamedService. So the service name could be given at runtime, not hard-coded as a const.
Context
I'm trying to implement a server to receive requests from runtime-decided or arbitrary service names sharing the same req&resp proto definition. This sounds not too hard from an HTTP point of view -- I hope the same tower::Service, without implementing NamedService, can be used for multiple service names.
I'm currently using the builder like most examples:
with the my_service being a modified copy from the output of codegen. But I was blocked by the fact that tonic::server::NamedService requires a hard-coded server name,
/// A trait to provide a static reference to the service's
/// name. This is used for routing service's within the router.
pub trait NamedService {
/// The `Service-Name` as described [here].
///
/// [here]: https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#requests
const NAME: &'static str;
}
And in router, add_service is the only method to configure the router depending on NamedService
With svc_name being decided at runtime.
3. Maybe more specific to my use case, it would also work if there's a way to replace the unimplemented fallback with my own service (so it handles all endpoints by default). Probably with something like
I can help create the patch either way. But before i do so I would really appreciate your feedback first.
Or are there other ways to implement this with the current API I missed? Thank you for your time!
The text was updated successfully, but these errors were encountered:
thanks @Palmik I've checked but still not sure how layer() could help? since it still seems to depend on add_service(svc) later on as the example, which still requires to be a NamedService. And I'm not suing grpc-web
So the namedservice stuff is mainly used by the tonic router, if you want to route stuff dynamically you will need to build your own transport that does its own routing. Currently, supporting dynamic services out of the box in tonic is a non-goal as eventually the transport module will be removed infavor of a better version, so making large changes like this won't be accepted right now.
Hello,
TLDR: I would like to have a way to add a service not implementing
NamedService
. So the service name could be given at runtime, not hard-coded as a const.Context
I'm trying to implement a server to receive requests from runtime-decided or arbitrary service names sharing the same req&resp proto definition. This sounds not too hard from an HTTP point of view -- I hope the same
tower::Service
, without implementing NamedService, can be used for multiple service names.I'm currently using the builder like most examples:
with the my_service being a modified copy from the output of codegen. But I was blocked by the fact that
tonic::server::NamedService
requires a hard-coded server name,And in router,
add_service
is the only method to configure the router depending onNamedService
Possible Solutions
I've thought of a few possible solns to this
add_service
but not relying onNamedService
. so it could be something likeWith svc_name being decided at runtime.
3. Maybe more specific to my use case, it would also work if there's a way to replace the
unimplemented
fallback with my own service (so it handles all endpoints by default). Probably with something likeI can help create the patch either way. But before i do so I would really appreciate your feedback first.
Or are there other ways to implement this with the current API I missed? Thank you for your time!
The text was updated successfully, but these errors were encountered: