我有一个最初未启动的计时器路由。我想从另一条路线激活它。我正在尝试使用骆驼的controlbus EIP模式。
// From my other route
.to("controlbus:route?routeId=fileConsumerRoute&action=start&async=true")
from("timer://camel-fileConsumerRoute?fixedRate=true&period=5s")
.routeId("fileConsumerRoute").noAutoStartup()
.log("Route is running");
我在控制总线后部的日志中看到正在恢复路由
上下文操作:[恢复]
,但计时器仍不触发。我看不到日志行“路由正在运行”
如何通过Controlbus激活计时器端点?
是否有另一种EIP模式或不同的方式来实现激活计时器端点?
答案 0 :(得分:0)
我知道我参加晚会很晚,但是,您可以使用Controlbus或类似的起止路线。如果有谓词,则进行其他布尔测试。
示例:
我们测试每个周期是否存在某种条件,并根据条件的结果执行操作...
<!-- Token Database -->
<route autoStartup="true" id="core.predix.tkndependencyCheckerRoute">
<from id="_from2" uri="timer://tkndbAvailable?fixedRate=true&period=30000"/>
<process id="_process2" ref="tkndbAvailableProcessor"/>
</route>
public class TknDbAvailableProcessor implements Processor {
private static final Logger LOG = LoggerFactory.getLogger(TknDbAvailableProcessor.class);
private TKNDataService tknDataService = null;
@Override
public void process(Exchange exchange) throws Exception {
ServiceStatus status = exchange.getContext().getRouteStatus("core.fleet.EnrichmentRoute");
if (null == tknDataService) {
if (status.isStarted()) {
exchange.getContext().stopRoute("core.fleet.EnrichmentRoute");
}
} else {
if (tknDataService.isTKNDataServiceAvailable()) {
if (status.isStopped()) {
exchange.getContext().startRoute("core.fleet.EnrichmentRoute");
}
} else {
if (status.isStarted()) {
exchange.getContext().stopRoute("core.fleet.EnrichmentRoute");
}
}
}
}
public void setDataService(TKNDataService dataService) {
this.tknDataService = dataService;
}
}
如果需要主单例路由(如果需要冗余)-在差异节点上,请使用带有ControlBus的JGroups群集
<bean class="org.apache.camel.component.jgroups.JGroupsFilters"
factory-method="dropNonCoordinatorViews"
id="dropNonCoordinatorViews" scope="prototype"/>
<bean class="org.apache.camel.component.jgroups.JGroupsExpressions"
factory-method="delayIfContextNotStarted"
id="delayIfContextNotStarted" scope="prototype">
<argument value="5000"/>
</bean>
<route autoStartup="true" id="FleetMainClusterControlRoute">
<from id="_from2" uri="jgroups:mainCluster?enableViewMessages=true&channelProperties=etc/jgroups.xml"/>
<filter id="filterNonCoordinatorViews">
<method ref="dropNonCoordinatorViews"/>
<threads id="threads1" threadName="ControlThreads">
<delay id="_delay1">
<ref>delayIfContextNotStarted</ref>
<log id="logCR" loggingLevel="INFO" message="Starting Main Cluster consumer!!!!!!!!!!!!!!!!!!!!!"/>
<to id="_toCR" uri="controlbus:route?routeId=core.predix.tkndependencyCheckerRoute&action=start&async=true"/>
</delay>
</threads>
</filter>
</route>