Thrift TNonblockingServer EOF 异常

Thrift TNonblockingServer EOF Exception

我已经在 java 中编写了服务器应用程序,在 groovy 中编写了客户端应用程序。 我的服务器收到请求并执行某事。我将 Thrift 与 TNonBlockingServer 一起使用。

    public static void nonBlockingServer(HbaseLayerService.Processor processor) {
            try {
                final Integer serverPort = ConfigurationManager.instance().getServerPort();
                TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(serverPort);
                TServer server = new TNonblockingServer(new TNonblockingServer.Args(serverTransport).processor(processor));

                server.serve();
            } catch (Exception e) {
                Throwables.propagate(e);
            }
        }

我的客户端发送~100Mb 数据

TTransport transport = new TFramedTransport(new TSocket('localhost', 12345, 100000))
transport.open()
TProtocol protocol = new TBinaryProtocol(transport);
HbaseLayerService.Client client = new HbaseLayerService.Client(protocol);
def putList = [] //~1500000 objects (string, string, string, int, byte[])
client.putEvent(new PutEventsOperation(putsToSend));

在此操作过程中出现错误:

Exception in thread "main" org.apache.thrift.transport.TTransportException
    at org.apache.thrift.transport.TIOStreamTransport.read(TIOStreamTransport.java:132)
    at org.apache.thrift.transport.TTransport.readAll(TTransport.java:86)
    at org.apache.thrift.transport.TFramedTransport.readFrame(TFramedTransport.java:129)
    at org.apache.thrift.transport.TFramedTransport.read(TFramedTransport.java:101)
    at org.apache.thrift.transport.TTransport.readAll(TTransport.java:86)
    at org.apache.thrift.protocol.TBinaryProtocol.readAll(TBinaryProtocol.java:429)
    at org.apache.thrift.protocol.TBinaryProtocol.readI32(TBinaryProtocol.java:318)
    at org.apache.thrift.protocol.TBinaryProtocol.readMessageBegin(TBinaryProtocol.java:219)
    at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:69)
    at communication_struct.thrift.HbaseLayerService$Client.recv_putEvent(HbaseLayerService.java:96)

此异常类型为 4:END_OF_FILE.

使用 TSimpleServer 一切正常,但我想在一个线程中进行一些连接并在队列中进行操作。

我终于找到了解决办法。 在这种特殊情况下,您应该将新尺寸添加到 TFramedTransport.Factory,如下所示:

TServer server = new TNonblockingServer(new TNonblockingServer.Args(serverTransport)
                    .processor(processor)
                    .transportFactory(new TFramedTransport.Factory(MAX_FRAMED_TRANSPORT_SIZE))
                    .protocolFactory(new TBinaryProtocol.Factory())
            );

同样的操作应该在客户端完成:

TTransport transport = new TFramedTransport(new TSocket('localhost', 12345), MAX_FRAMED_TRANSPORT_SIZE)

就我而言 MAX_FRAMED_TRANSPORT_SIZE = 256 * 1024 * 1024.