如何更改Apache thrift框架大小

时间:2015-09-13 18:02:51

标签: java thrift

我遇到了异常

Caused by: org.apache.thrift.transport.TTransportException: Frame size (1937007972) larger than max length (16384000)!
    at org.apache.thrift.transport.TFramedTransport.readFrame(TFramedTransport.java:137) ~[libthrift-0.9.2.jar:0.9.2]
    at org.apache.thrift.transport.TFramedTransport.read(TFramedTransport.java:101) ~[libthrift-0.9.2.jar:0.9.2]
    at org.apache.thrift.transport.TTransport.readAll(TTransport.java:86) ~[libthrift-0.9.2.jar:0.9.2]
    at org.apache.thrift.protocol.TBinaryProtocol.readStringBody(TBinaryProtocol.java:380) ~[libthrift-0.9.2.jar:0.9.2]
    at org.apache.thrift.protocol.TBinaryProtocol.readMessageBegin(TBinaryProtocol.java:230) ~[libthrift-0.9.2.jar:0.9.2]
    at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:69) ~[libthrift-0.9.2.jar:0.9.2]

有没有办法将尺寸更改为无限制,因为我不确定我的数据大小是多少。

1 个答案:

答案 0 :(得分:2)

AFAIK有一个针对Java的特定CTOR,可以传递the server sideclient side的帧大小。

客户CTOR

/** 
* Constructor wraps around another transport 
*/ 
public TFramedTransport(TTransport transport, int maxLength) { 
   transport_ = transport; 
   maxLength_ = maxLength; 
 } 

服务器端工厂,包括CTOR

public static class Factory extends TTransportFactory { 
  private int maxLength_; 

  public Factory() { 
    maxLength_ = TFramedTransport.DEFAULT_MAX_LENGTH; 
  } 

  public Factory(int maxLength) { 
    maxLength_ = maxLength; 
  } 

  @Override 
  public TTransport getTransport(TTransport base) { 
     return new TFramedTransport(base, maxLength_); 
  } 
} 

因此解决方案是在构造Thrift协议/传输堆栈时指定它。