[英]Synchronous HTTP call in Netty
我的應用程序收到一個HTTP請求,並且在管道的中間,調用了另一台服務器以獲取支持信息。 直到該響應返回,初始的HTTP請求才能繼續通過管道。 我無法從I / O線程使用awaitUninterruptability()
,所以進行這些調用的最佳方法是什么,因此我不會阻止Netty的事件循環,而是將客戶端的管道置於等待狀態,直到我的調用返回為止管道繼續嗎?
瑞安這聽起來不是個好主意。
我認為您最好使用這樣的方法:
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中處理它。 但是我想你明白了。
我猜你需要一個ExecutionHandler 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.