我的应用程序收到一个HTTP请求,在流水线的中间,调用另一个服务器以获取支持信息。在响应返回之前,最初的HTTP请求不能继续通过管道。我不能从I/O线程使用awaitUninterruptability(),那么进行这些调用的最好方法是什么,这样我就不会阻塞Netty的事件循环,而是将客户端的流水线搁置,直到我的调用返回并告诉流水线继续进行?
发布于 2012-04-29 02:32:17
莱恩这听起来不是个好主意..
我认为你最好使用这样的东西:
public class HttpHandler extends SimpleChannelUpstreamHandler{
@Override
public void messageReceived(final ChannelHandlerContext ctx, final MessageEvent e) throws Exception {
otherChannel.write(yourRequet).addListener(new ChannelFutureListener() {
public void operationComplete(ChannelFuture future) throws Exception {
// once the write is done we can continue in the pipeline
ctx.sendUpstream(e);
}
});
// the event stops here to get processed
}
}如果您需要等待响应,则需要在另一个SimpleChannelUpstreamHandler中处理它。但我想你已经明白了..
发布于 2012-04-28 19:34:35
我想你需要一个ExecutionHandler。
https://stackoverflow.com/questions/10358938
复制相似问题