Java I';I’我想在一种交通工具上使用多种服务(节俭)

Java I';I’我想在一种交通工具上使用多种服务(节俭),java,handler,thrift,Java,Handler,Thrift,我想创建几个服务,我想用不同的标识符来使用它们。 所以我的意思是: 我有一个用户和项目服务。 我想同时使用这些 我的意思是我可以在xmlrpc上的“handlermap”中添加更多的“服务” 我想在节俭方面也这样做 下面是一个简单的例子: 节俭 typedef i64 UserId struct Bonk { 1: string message, 2: i32 type } struct Insanity { 1: map<Bonk, UserId> userMap

我想创建几个服务,我想用不同的标识符来使用它们。 所以我的意思是:

我有一个用户和项目服务。 我想同时使用这些

我的意思是我可以在xmlrpc上的“handlermap”中添加更多的“服务”

我想在节俭方面也这样做

下面是一个简单的例子: 节俭

typedef i64 UserId

struct Bonk
{
  1: string message,
  2: i32 type
}

struct Insanity
{
  1: map<Bonk, UserId> userMap,
  2: list<Bonk> xtructs
}



service ThriftTest
{
  void         testVoid(),
  string       testString(1: string test),
  byte         testByte(1: byte test),
  i32          testI32(1: i32 test),
  i64          testI64(1: i64 test),
  double       testDouble(1: double test),
  list<map<i32,i32>> testMap(1: map<i32,i32> test),
  map<string,string> testStringMap(1: map<string,string> test),
  set<i32>     testSet(1: set<i32> test),
  map<i32,map<i32,i32>> testMapMap(1: i32 test),
  map<UserId, map<i32,Insanity>> testInsanity(1: Insanity argument)
}
这是我的大问题,我不能添加多个服务器实例


提前感谢您的帮助。

RPC调用在没有“targetService”字段的TMessage结构中通过有线传输。因此,如果不将此字段添加到TMessage并重新编译thrift,就无法将多个服务绑定到单个端口

可以通过实现类似于TsimpleServer(或任何其他TServer)的定制TServer来进行黑客攻击

服务器应读取循环中的目标服务并获得相应的处理器:

      ...
      inputProtocol = inputProtocolFactory_.getProtocol(inputTransport);
      outputProtocol = outputProtocolFactory_.getProtocol(outputTransport);
      do {
        String target = inputProtocol.readString();
        processor = processorFactoryMap.get(target).getProcessor(client);
      while (processor.process(inputProtocol, outputProtocol));
      ...
客户端应在每条消息前面加上目标服务字符串。这可以通过在自定义协议中包装TBinaryProtocol来实现:

public void writeMessageBegin(TMessage message) throws TException {
    wrapped.writeString(target);
    wrapped.writeMessageBegin(message);
}
这种方法的主要缺点是失去了与其他客户机的互操作性。因此,最好在不同的端口上启动两个不同的Tserver,或者在一个thrift服务中定义所有方法,然后将调用委托给适当的处理程序。

多路复用服务(本质上这就是您在这里想要做的)现在正在集成。已经有许多可用语言的补丁,或者已经被接受,或者正在审查中

这是一个很好的开始

PS:欢迎评论和投稿;-)

      ...
      inputProtocol = inputProtocolFactory_.getProtocol(inputTransport);
      outputProtocol = outputProtocolFactory_.getProtocol(outputTransport);
      do {
        String target = inputProtocol.readString();
        processor = processorFactoryMap.get(target).getProcessor(client);
      while (processor.process(inputProtocol, outputProtocol));
      ...
public void writeMessageBegin(TMessage message) throws TException {
    wrapped.writeString(target);
    wrapped.writeMessageBegin(message);
}