You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by Gianni <gi...@vi-grade.com> on 2021/03/31 08:13:58 UTC

Client backward compatibility switching from TSimpleServer to TNonblockingServer

Dear All,
I implemented my thrift service in c++ basically as follows:

      std::shared_ptr< apache::thrift::TProcessor > processor(new 
Processor(service));
      std::shared_ptr< apache::thrift::transport::TServerTransport > 
serverTransport(new apache::thrift::transport::TServerSocket(port));
      std::shared_ptr< apache::thrift::transport::TTransportFactory > 
transportFactory(new 
apache::thrift::transport::TBufferedTransportFactory());
      std::shared_ptr< apache::thrift::protocol::TProtocolFactory > 
protocolFactory(new apache::thrift::protocol::TBinaryProtocolFactory());
      server = std::make_shared< apache::thrift::server::TSimpleServer 
 >(processor, serverTransport, transportFactory, protocolFactory);

while the client was implemented in this way:

     std::shared_ptr< apache::thrift::transport::TSocket > socket(new 
apache::thrift::transport::TSocket(serviceIp, servicePort));
     socket->setConnTimeout(connectionTimeout);
     transport = std::make_shared< 
apache::thrift::transport::TBufferedTransport >(socket);
     transport->open();
     _service = std::make_shared< Service >(std::make_shared< 
apache::thrift::protocol::TBinaryProtocol >(transport));

Then I needed to have a TNonblockingServer. So I had to change my server 
to this implementation:

     std::shared_ptr< apache::thrift::TProcessor > processor(new 
Processor(service));
     std::shared_ptr< apache::thrift::protocol::TProtocolFactory > 
protocolFactory(new apache::thrift::protocol::TBinaryProtocolFactory());
     std::shared_ptr< 
apache::thrift::transport::TNonblockingServerSocket > serverSocket(new 
apache::thrift::transport::TNonblockingServerSocket(port));
     server = std::make_shared< 
apache::thrift::server::TNonblockingServer >(processor, serverSocket);

The clients did not work as they were so I had to change also the client 
implementation to use a TFramedTransport instead of a 
TBufferedTransport. This is a pain since I had to upsate all the old 
clients not just the server.
Is there a way to make old clients working with the new Nonblocking server?

Best regards,
Gianni