首先,我只是想让您知道我是骆驼的新手,最近我掌握了它的主要概念。
我正在尝试使用ActiveMQ作为代理使用Apache-Camel并使用故障转移构造将jms-component用作负载均衡器的客户端来创建一个基本的工作示例。所有这些操作仅使用Java DSL(如果可能)完成。
该示例包含4个主要应用程序,分别称为MyApp-A,MyApp-B,MyApp-C和MyApp-D。在正常情况下,MyApp-A从计算机读取文件,然后将其转换为消息。然后,它将消息发送到MyApp-B,然后MyApp-B将消息发送到MyApp-C。

但是,存在失败的情况。在这种情况下,MyApp-A无法将消息发送到MyApp-B。然后,它将消息发送到MyApp-D,后者又将其发送到MyApp-C。

波纹管是我的MyApp-A代码
public class MyApp-A {
public static void main(String args[]) throws Exception {
// create CamelContext
CamelContext context = new DefaultCamelContext();
// connect to embedded ActiveMQ JMS broker
ConnectionFactory connectionFactory =
new ActiveMQConnectionFactory("vm://localhost");
context.addComponent("jms",
JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
// add our route to the CamelContext
context.addRoutes(new RouteBuilder() {
@Override
public void configure() {
from("file:data/inbox?noop=true")loadbalancer().failover().to("MyApp-B:incomingOrders").to("MyApp-D:incomingOrders").end();
}
});
// start the route and let it do its work
context.start();
Thread.sleep(10000);
// stop the CamelContext
context.stop();
}
}
Run Code Online (Sandbox Code Playgroud)
我曾考虑过使用camel-ftp,但由于MyApp-C不知道MyApp-B死了,也不知道它必须从MyApp-D中获取,因此无法使用。 …