Service Multiplexing using Apache Thrift

本秂侑毒 提交于 2019-12-19 09:06:29

问题


Server code:

            TMultiplexedProcessor processor = new TMultiplexedProcessor();

            processor.registerProcessor(
                "AddService",
                new AddService.Processor(new AddHandler()));

            processor.registerProcessor(
                "MultiplyService",
                new MultiplyService.Processor(new MultiplyHandler()));

            TServerTransport serverTransport = new TServerSocket(7911);



            TSimpleServer server = new TSimpleServer(new TSimpleServer.Args(serverTransport).
                   processor(processor));

            System.out.println("Starting server on port 7911 ...");
            server.serve();

Client Code:

    TFramedTransport transport;

   transport = new TFramedTransport(new TSocket("localhost", 7911));  
   transport.open();  


   TProtocol protocol = new TBinaryProtocol(transport);

   System.out.println("1");
   TMultiplexedProtocol mp = new TMultiplexedProtocol(protocol, "AddService");
   AddService.Client service = new AddService.Client(mp);

   System.out.println("2");
   TMultiplexedProtocol mp2 = new TMultiplexedProtocol(protocol, "MultiplyService");
   MultiplyService.Client service2 = new MultiplyService.Client(mp2);

   System.out.println("3");

   System.out.println(service.add(2,2));
   System.out.println(service2.multiply(2000,200));

But when I am running the server(listening on port 7911) and the client, the client doesnt process the last two calls to the add/multiply functions.

I could debug that the arguments have been sent to the server, but the server is not able to process them.

Any pointers as to what i am missing?


回答1:


Not tested, but it looks very much like as if you run two different protocol stacks on server and client. Try this:

TMultiplexedProcessor processor = new TMultiplexedProcessor();

processor.registerProcessor(
    "AddService",
    new AddService.Processor(new AddHandler()));

processor.registerProcessor(
    "MultiplyService",
    new MultiplyService.Processor(new MultiplyHandler()));

TServerTransport serverTransport = new TServerSocket(7911);

TTransportFactory factory = new TFramedTransport.Factory();

TServer.Args args = new TServer.Args(serverTransport);
args.processor(processor);
args.transportFactory(factory);
TSimpleServer server = new TSimpleServer(args);

System.out.println("Starting server on port 7911 ...");
server.serve();


来源:https://stackoverflow.com/questions/19614648/service-multiplexing-using-apache-thrift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!