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
Allow binding more than one Thrift service at the same path #2164
Comments
For example, we could allow a user to build a |
Another food for thought: a user wants to specify different decorators for different Thrift service types. It is currently doable by writing a decorating public class MyRpcDecorator extends SimpleDecoratingRpcService {
final Service<RpcRequest, RpcResponse> decoratorA;
final Service<RpcRequest, RpcResponse> decoratorB;
public MyRpcDecorator(Service<RpcRequest, RpcResponse> delegate) {
super(delegate)
decoratorA = new DecoratorForServiceA(delegate);
decoratorB = new DecoratorForServiceB(delegate);
}
@Override
public RpcResponse serve(ServiceRequestContext ctx, RpcRequest req) throws Exception {
if (req.serviceType() == ServiceA.class) {
return decoratorA.serve(ctx, req);
} else {
return decoratorB.serve(ctx, req);
}
}
} Maybe we need to find a way to make this kind of diversion easier.. |
I can take a look at this. Is it fine? |
@sivaalli Absolutely! Thanks a lot for looking into this. ❤️ |
Hi @trustin , I was able to look into this recently. I had a couple of questions and wanted to reach out to you before starting to write any code.
And when a server builder is created like this:
Any request with path |
@sivaalli Thanks for looking into this issue first of all.
Yes, we should look for a function in the order as specified when building a THttpService. Also, if FooService and BarService both have foo(), the FooService, which was specified first, will be chosen. Please also keep in mind that we also need to support TMultiplexed, which is supported via of(Map) factory method. Let me know if you are not familiar with TMultiplexed - I can elaborate on it. |
Thank you for quick response @trustin. I'm currently understanding/learning about how thrift works internally. I was able to understand that TMultiplexed is a way to bind multiple thrift services to the same http path by assigning a service name. And the service name is passed in client request to target a single thrift service. Is my understanding correct? Please correct me if it is not so. |
@sivaalli That's correct! 👍 Ideally, it will be awesome if we have a builder API which allows mapping multiple services with and/or without multiplexing:
If service name does not exist in the request, FooService or BarService will be chosen. If service name is "a", AService or BService would be chosen. |
This Builder API idea looks good. I will start working on this 😄 |
Hi @trustin, do you think that entire If each service can have a different default serialization format then we could potentially match the function that supports a specific serialization format from the request. Do you think this is necessary? |
@sivaalli That's a good question. I think we can add such an option later if requested by users. Meanwhile, let's stick to the current behavior - using the same default/available serialization formats. |
This PR will allow multiple Thrift services to be bind on an HTTP path, also supporting `TMultiplexed ` protocol. **Changes**: 1. `ThriftFunction` holds reference of the implementation 2. `ThriftServiceMetadata` now can take a list of thrift service implementations and can hold a mapping between the method name and `ThriftFunction`. 3. Introduced `THttpServiceBuilder` to fluently build instance of `THttpService`. **Deprecations**: 1. API's in`THttpService` that take `Map<String, ?>` are deprecated in favor of `THttpServiceBuiler.ofService(String serviceName, Object implementation)`. **Breaking changes**: 1. `ThriftCallService` factory method with signature `ThriftCallService of(Map<String, ? extends Iterable<?>> implementation)` is changed to `ThriftCallService of(Map<String, ? extends Iterable<?>> implementations)` Closes: #2164
This PR will allow multiple Thrift services to be bind on an HTTP path, also supporting `TMultiplexed ` protocol. **Changes**: 1. `ThriftFunction` holds reference of the implementation 2. `ThriftServiceMetadata` now can take a list of thrift service implementations and can hold a mapping between the method name and `ThriftFunction`. 3. Introduced `THttpServiceBuilder` to fluently build instance of `THttpService`. **Deprecations**: 1. API's in`THttpService` that take `Map<String, ?>` are deprecated in favor of `THttpServiceBuiler.ofService(String serviceName, Object implementation)`. **Breaking changes**: 1. `ThriftCallService` factory method with signature `ThriftCallService of(Map<String, ? extends Iterable<?>> implementation)` is changed to `ThriftCallService of(Map<String, ? extends Iterable<?>> implementations)` Closes: line#2164
A user wants to write a Thrift proxy server that forwards the requests to their corresponding remote Thrift services where each Thrfit service has different IDLs, e.g.
If a client calls
foo()
thenFooService
would be invoked.bar()
thenBarService
.Currently, a user has to use
TMultiplexed
protocol and specify a service name explicitly.Once this feature is implemented, a proxy Thrift server could provide a union/merged view of multiple Thrift services without using
TMultiplexed
protocol, allowing a user to split/merge their services without affecting the public API.The text was updated successfully, but these errors were encountered: