Skip to content
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

Same method name in difference services lead to error: "Multiple methods named 'send' are annotated with @ThriftMethod in the given services" #110

Open
symfu opened this issue Aug 2, 2019 · 2 comments

Comments

@symfu
Copy link

symfu commented Aug 2, 2019

Given two services:

@ThriftService
public interface ServiceOne {
    @ThriftMethod
    boolean send(String message);
}

@ThriftService
public interface ServiceTwo {
    @ThriftMethod
    boolean send(String message);
}

DriftServer will throw an exception complains that ""Multiple methods named 'send' are annotated with @ThriftMethod in the given services"".

It seems that difference services can't have a method with the same name?

Relative code (io/airlift/drift/server/DriftServerMethodInvoker.java:58):

package io.airlift.drift.server;
class DriftServerMethodInvoker implements ServerMethodInvoker {
    ...
    public DriftServerMethodInvoker(
            ThriftCodecManager codecManager,
            Collection<DriftService> services,
            List<MethodInvocationFilter> filters,
            MethodInvocationStatsFactory methodInvocationStatsFactory)
    {
        Map<String, ServiceMethod> processorMap = new HashMap<>();
        ImmutableMap.Builder<String, MethodInvocationStat> stats = ImmutableMap.builder();
        for (DriftService service : services) {
            ThriftServiceMetadata serviceMetadata = new ThriftServiceMetadata(service.getService().getClass(), codecManager.getCatalog());
            for (ThriftMethodMetadata thriftMethodMetadata : serviceMetadata.getMethods().values()) {
                if (processorMap.containsKey(thriftMethodMetadata.getName())) {

                    throw new IllegalArgumentException(format("Multiple methods named '%s' are annotated with @ThriftMethod in the given services", thriftMethodMetadata.getName()));
--------------------^  HERE

                }
                ServiceMethod serviceMethod = new ServiceMethod(codecManager, service.getService(), thriftMethodMetadata, filters);
                processorMap.put(thriftMethodMetadata.getName(), serviceMethod);
                if (service.isStatsEnabled()) {
                    stats.put(thriftMethodMetadata.getName(), methodInvocationStatsFactory.getStat(serviceMetadata, service.getQualifier(), serviceMethod.getMethodMetadata()));
                }
            }
        }
        ...
    }
` 
@electrum
Copy link
Member

electrum commented Aug 2, 2019

This is correct. Unfortunately, the Thrift protocol does not have any namespace for services. In fact, there’s no concept of “service” on this the wire. There is only the method name.

@tanwov
Copy link

tanwov commented Sep 17, 2020

Thrift's TMultiplexedProtocol may be an ungraceful way to use the service name as namespace. It converts the method name to serviceName:methodName . And we can @ThriftMethod(serviceName:methodName) to handle multiplex protocol.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants