我想在一个传输上使用多个服务(节俭)(two one thrift)

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

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

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

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

http://ws.apache.org/xmlrpc/server.html
phm.addHandler("Users",
             Users.class); 
phm.addHandler("Projects",
               Projects.class);

我想在节俭中做同样的事情。

这是一个简单的例子:test.thrift

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)
}

然后我创建一个 implementatino,然后将其添加到 TServer 的实例。

Users.Processor users_proccesor = new Users.Processor(New UsersImpl());
Projects.Processor project_processor = new Projects.Processors(new ProjectsImp());
// I would like to add Users and Projects  
ThriftTest.Processor prc = new ThriftTest.Processor(new ThiftTestImp());
            TServerTransport serverTransport = new TServerSocket(9090);
            TServer server = new TSimpleServer(new Args(serverTransport).processor( prc ));

这里是我的大问题,我不能添加服务器的多个实例。

提前感谢您的帮助。

7

Multiplexed Services(本质上这就是你想在这里做的)现在正在集成。已经有一些可用的语言的补丁,要么已经被接受,要么正在。

https://issues.apache.org/jira/browse/THRIFT-563是一个好的开始。

PS:欢迎审阅者和贡献;-)

5

RPC 调用通过 TMessage 结构中没有 'targetService' 字段的线路传输。因此,没有简单的方法将多个服务绑定到单个端口,而无需将此字段添加到 TMessage 并重新编译节俭。

可以通过实现类似于 TSimpleSever(或任何其他 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);
}

这种方法的主要缺点是失去与其他客户端的互操作性。因此,可能最好在不同的端口上启动两个不同的 TServers,或者在单个节俭服务中定义所有方法,然后将调用委托给适当的处理程序。

本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处

(591)
geopandas如何加入op“内”和“相交”不同
上一篇
Terraform更新在AWS控制台上创建的现有Lambda函数
下一篇

相关推荐

发表评论

登录 后才能评论

评论列表(43条)