Thrift中的会话管理 [英] Session management in Thrift
问题描述
我似乎找不到任何有关如何在Thrift的RPC框架中完成会话管理的文档.
I can't seem to find any documentation on how session management is supposed to be done in Thrift's RPC framework.
我知道我可以做
TServer.setServerEventHandler(myEventHandler);
观察对createContext
(在建立连接时调用)和processContext
(在每次方法调用之前调用)的调用.尽管如此,我仍必须将这些消息中维护的任何会话状态传递到处理程序本身.
and observe calls to createContext
(called when a connection is established) and processContext
(called before every method call). Still, I have to get whatever session state I maintain in those message into the handler itself.
那我该如何在我的处理程序中访问会话信息?
So how can I access session information in my handlers?
推荐答案
不确定我的问题中是否还没有使用ServerEventHandler
方法的方法,但这是我能够为每个方法创建一个处理程序的方法连接.
Not sure if there isn't also a way to use the ServerEventHandler
approach mentioned in my question, but here's how I was able to create one handler per connection.
不是一次提供包含处理程序实例的单例处理器实例,就像这样:
Rather than providing a singleton processor instance, containing a handler instance, once, like this:
XProcessor<XHandler> processor = new X.Processor<XHandler>(new XHandler());
TServer server = new TSimpleServer(new TServer.Args(serverTransport)
.processor(processor));
我改为创建并提供一个TProcessorFactory
:
I instead create and provide a TProcessorFactory
:
TProcessorFactory processorFactory = new TProcessorFactory(null)
{
public TProcessor getProcessor(TTransport trans)
{
return new X.Processor<XHandler>(new XHandler());
}
};
TServer server = new TSimpleServer(new TServer.Args(serverTransport)
.processorFactory(processorFactory));
这篇关于Thrift中的会话管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!