【发布时间】:2015-05-10 10:50:04
【问题描述】:
我刚开始使用 Apache Camel,我对异步 http 客户端 (AHC) 看似违反直觉的默认行为感到好奇。在使用来自 ActiveMQ 的消息时,我无法让它以非阻塞方式运行。
我的路线如下所示:
@Component
public class Broadcaster extends RouteBuilder {
@Override
public void configure() throws Exception {
errorHandler(deadLetterChannel("activemq:failed.messages"));
from("activemq:outbound.messages")
.setExchangePattern(ExchangePattern.InOnly)
.recipientList(simple("ahc:${in.header[PublishDestination]}"))
.end();
}
}
我将几条消息排入队列,其中一半发送到延迟的网络服务器,另一半发送到正常的。我希望看到快速服务器立即消耗所有正常消息,并且随着时间的推移逐渐消耗慢速消息。然而,这是在快速网络服务器上观察到的行为:
00:24:02.585, <hello>World</hello>
00:24:03.622, <hello>World</hello>
00:24:04.640, <hello>World</hello>
00:24:05.658, <hello>World</hello>
如您所见,每个记录的请求之间恰好有一秒,对应于慢速服务器上的人为 1 秒延迟。根据路由时间,看起来 JMS 消费者正在等待 AHC 完成,然后才消费队列中的下一条消息:
Processor Elapsed (ms)
[activemq://outbound.messages ] [ 1020]
[setExchangePattern[InOnly] ] [ 0]
[ahc:${in.header[PublishDestination]}} ] [ 1018]
在这些情况下,我是否应该明确使用异步生产者并编写回调处理程序,还是我还缺少其他东西?谢谢!
【问题讨论】:
标签: apache-camel activemq asynchttpclient