java - Apache Camel Route 正在自动启动
问题描述
当我启动主类时,路由加载文件会自动启动。
在异常情况下,进程应该何时完成。它一次又一次地启动loadfile。
它应该从定时器开始,然后应该调用 loadfile 路由,但是 loadfile 是独立启动的,也从定时器开始。
CamelContext context = new DefaultCamelContext(sr);
try {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
onException(Exception.class)
.log(LoggingLevel.INFO, "Extype:${exception.message}")
.stop();
from("timer://alertstrigtimer?period=60s&repeatCount=1")
.startupOrder(1)
.log(LoggingLevel.INFO, "*******************************Job-Alert-System: Started: alertstrigtimer******************************")
.to("direct:loadFile").stop();
from("direct:loadFile").routeId("loadfile")
.log(LoggingLevel.INFO, "*******************************Job-Alert-System: Started: direct:loadFile******************************")
.from(getTriggerFileURI(getWorkFilePath(), getWorkFileName())).choice()
.
.
});
context.start();
Thread.sleep(40000);
以下是日志:
[main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.21.1 (CamelContext: camel-1) is starting
[main] INFO org.apache.camel.management.ManagedManagementStrategy - JMX is enabled
[main] INFO org.apache.camel.impl.converter.DefaultTypeConverter - Type converters loaded (core: 194, classpath: 14)
[main] INFO org.apache.camel.impl.DefaultCamelContext - StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
[main] INFO org.apache.camel.impl.DefaultCamelContext - Route: route1 started and consuming from: timer://alertstrigtimer?period=60s&repeatCount=1
[main] INFO org.apache.camel.impl.DefaultCamelContext - Skipping starting of route loadfile as its configured with autoStartup=false
[main] INFO org.apache.camel.impl.DefaultCamelContext - Route: loadDataAndAlerts started and consuming from: direct://loadDataAndAlerts
[main] INFO org.apache.camel.impl.DefaultCamelContext - Total 4 routes, of which 2 are started
[main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.21.1 (CamelContext: camel-1) started in 0.761 seconds
[Camel (camel-1) thread #1 - timer://alertstrigtimer] INFO route1 - *******************************Job-Alert-System: Started: alertstrigtimer******************************
[Camel (camel-1) thread #2 - timer://alertstrigtimer] INFO loadfile - *******************************Job-Alert-System: Started: direct:loadFile******************************
[Camel (camel-1) thread #1 - file://null] INFO loadfile - *******************************Job-Alert-System: Started: direct:loadFile******************************
解决方案
问题可能是由.from(getTriggerFileURI(getWorkFilePath(), getWorkFileName()))
loadfile 路由中的这一行引起的。具有多个来自端点的路由称为多输入,并且此模式已在 Camel 3.x 中删除。
从红帽,
from("URI1").from("URI2").from("URI3").to("DestinationUri");
...,来自每个输入端点 URI1、URI2 和 URI3 的交换彼此独立并在单独的线程中处理。实际上,您可以将前面的路由视为等效于以下三个单独的路由:
from("URI1").to("DestinationUri");
from("URI2").to("DestinationUri");
from("URI3").to("DestinationUri");
不要使用来自端点的多个(额外的独立输入),而是尝试内容丰富器模式(pollEnrich用于文件组件)。
推荐阅读
- shell - 模式匹配“hdfs ds -ls”输出时如何忽略时间戳?
- stealjs - 全局/窗口分配或控制台导入失败
- javascript - ol.source.Vector 实例的 .getFeatures() 方法在控制台中工作,但不在脚本中
- javascript - 如何在 Sweet Alert 弹出消息内容中获得价值?
- html - 无论设备类型如何,如何在 HTML 和 CSS 中将动画图像和非动画文本居中?
- http - Nginx 客户端发送了重复的标题行?
- java - 哪一个执行得更快?sql order by 或 java PriorityQueue 或任何其他?
- reporting-services - SSRS 向下钻取报告未正确过滤参数
- python - 使用循环返回顺序在列表中搜索字符串
- python - 如何使用 executemany 将每个 Key 中的第一个值写入数据库