1. 通过将请求放入JMS代理来调用外部服务 2. 等待它的响应,在另一个线程上,因此原始线程不会被阻塞。 3. 如果请求超时,则重新从步骤2开始(这部分可以通过轮询完成); 否则继续 4. 处理响应 我的测试路由实现
// Simulate receiving message from upstream
from("direct:jmsStart")
.setExchangePattern(ExchangePattern.InOnly)
.validate(new TestValidator("Some basic validation"))
.to("seda:sell");
// Sell Flow Starts
from("seda:sell")
.transform(new TestTransformer("Convert to internal data structure"))
.validate(new TestValidator("ValidateSellStatus"))
.process(new TestProcessor("Prepare request to external system"))
.process(new TestProcessor("Persist the request to DB")) // <== Any better persistence suggestion??
.to("seda:jmsRequestToExternal");
// Simulate External System Processing
from("seda:jmsRequestToExternal")
.log(LoggingLevel.INFO, LOGGER, "External System Processing...")
.delay(1000).to("seda:jmsReplyFromExternal");
// External System response received
from("seda:jmsReplyFromExternal")
.process(new TestProcessor("Mark Complete"))
.log(LoggingLevel.INFO, LOGGER, "Send reply to upstream");
// Trigger retry - resend those requests without a response
from("timer://poller?period=30000")
.process(new TestProcessor("Get pending requests from DB")) // <== Any better persistence suggestion??
.to("seda:jmsRequestToExternal");
为了实现低延迟,所有路由/子路由都不应互相阻塞。请问是否有更好的实现方式可以达到同样的效果?我了解到,Camel上的重新传递机制似乎依赖于阻塞超时或异常机制,这可能不适合低延迟应用程序。