- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
此处使用 Apache 2.11.0。我正在编写一个基于 Camel 的小应用程序(使用 Spring XML),它从队列 (inputQueue
) 中获取消息,聚合它们,处理聚合的批处理,然后发送生成的报告。我想将此应用程序 (widget-reporter.war
) 部署到多个 Tomcat 实例并将它们集群,这样如果一个节点出现故障,它仍在其他节点上运行并且报告仍会得到生成。
目前路由的伪代码如下:
<camelContext id="myCamel" xmlns="http://camel.apache.org/schema/spring">
<route id="myRoute">
<from uri="activemq:queue:inputQueue" />
<aggregate strategyRef="myStrategy" completionSize="500">
<correlationExpression>
<xpath>/fizz/buzz</xpath>
</correlationExpression>
<to uri="bean:reportGenerator?method=runReport"/>
</aggregate>
</route>
</camelContext>
因此,如您所见,我们从 inputQueue
中取出消息,将它们发送到聚合器(在 xpath 表达式上关联它们),在达到 500 条消息后,我们发送聚合交换关闭到 reportGenerator
。
我在本地(1 个节点)完美地运行了它。现在我正尝试将此应用程序部署到多个 Tomcat 实例,但我只希望它一次在 1 个节点上运行。换句话说,如果我将这个应用程序部署到 5 个 Tomcat 实例,我不希望 5 个 Tomcat 同时从 inputQueue
消耗:在任何给定时间只有 1 个应该运行,并且其他 4 个应该处于空闲状态,等待主节点故障转移到它们。
看起来 Camel Quartz
允许这样的集群,但问题是它要求我以 quartz://
端点开始我的路线,而不是 activemq
。所以我必须有这样的东西(这是行不通的):
<route id="myRoute">
<from uri="quartz://runWidgetReporterExclusively?cron=0+15,45+0-16+?+*+SAT" />
<!-- Can't have 2 consecutive "from" endpoints... -->
<from uri="activemq:queue:inputQueue" />
<aggregate strategyRef="myStrategy" completionSize="500">
<correlationExpression>
<xpath>/fizz/buzz</xpath>
</correlationExpression>
<to uri="bean:reportGenerator?method=runReport"/>
</aggregate>
</route>
有人知道我该怎么做吗:
最佳答案
使用 camel-zookeeper为此启用 RoutePolicy...
ZooKeeper allows for very simple and effective leader election out of the box; This component exploits this election capability in a RoutePolicy to control when and how routes are enabled. This policy would typically be used in fail-over scenarios, to control identical instances of a route across a cluster of Camel based servers. A very common scenario is a simple 'Master-Slave' setup where there are multiple instances of a route distributed across a cluster but only one of them, that of the master, should be running at a time. If the master fails, a new master should be elected from the available slaves and the route in this new master should be started.
关于java - 如何将 Camel Quartz 集群与队列消费结合使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21553252/
我是一名优秀的程序员,十分优秀!