我正在尝试使用camel执行shell脚本并尝试以下代码,一切看起来很好,它的启动路线但我有以下2个问题
以下是我正在使用的路线
@component
public class ShellRoute extends RouteBuilder
{
@override
public void configure()
{
final Logger logger = LoggerFactory.getLogger(ShellRoute.class);
logger.info("shellRoute");
boolean startupRoute=true;
from("direct:start")
.log(LoggingLevel.INFO, "Enter into Route:")
.routeID("ShellRoute")
.autoStartup(startupRoute)
.onException(Exception.class);
.logExhausted(false)
.logStackTrace(false)
.end()
.log(LoggingLevel.INFO, "Starting Script:")
.to("exec:./run_setup.sh?args=dev")
.log(LoggingLevel.INFO, "End of Script:");
}
}
以下是日志:
2017-09-29 08:32:53 INFO版本:30 - HV000001:Hibernate Validator 5.2.4.Final
2017-09-29 08:32:53 INFO SupportMain:48 - 使用PID 13002在VDDP13C-52C8C99.mis.lmig.com上启动SupportMain (/数据/用户数据/工作区/ ClaimDownload /支持/目标/类 由mani在/ data / userdata / workspaces / ClaimDownload / support)
启动2017-09-29 08:32:53 INFO SupportMain:669 - 以下个人资料有效:本地
2017-09-29 08:32:53 INFO AnnotationConfigApplicationContext:581 - 刷新 org.springframework.context.annotation.AnnotationConfigApplicationContext@776aec5c: 启动日期[Fri Sep 29 08:32:53 EDT 2017];上下文层次结构的根 2017-09-29 08:32:55 INFO PostProcessorRegistrationDelegate $ BeanPostProcessorChecker:328 - Bean 'class的'org.apache.camel.spring.boot.CamelAutoConfiguration' org.apache.camel.spring.boot.CamelAutoConfiguration $$ EnhancerBySpringCGLIB $$ 9509da1] 不适合所有BeanPostProcessors处理(for 示例:不符合自动代理的条件)
2017-09-29 08:32:56 INFO DefaultTypeConverter:56 - 加载209型转换器
2017-09-29 08:32:57 INFO AnnotationMBeanExporter:431 - 在启动时为JMX曝光注册bean
2017-09-29 08:32:57 INFO ShellRoute:33 - ShellRoute
2017-09-29 08:32:57 INFO RoutesCollector:148 - 从以下位置加载其他Camel XML路由:classpath:camel / * .xml
2017-09-29 08:32:57 INFO RoutesCollector:162 - 加载其他Camel XML,来自:classpath:camel-rest / * .xml
2017-09-29 08:32:57 INFO SpringCamelContext:2800 - Apache Camel 2.17.2(CamelContext:camel-1)正在启动
2017-09-29 08:32:57 INFO ManagedManagementStrategy:191 - 启用JMX
2017-09-29 08:32:57 INFO DefaultRuntimeEndpointRegistry:203 - 运行时端点注册表处于扩展模式收集使用情况 所有传入和传出端点的统计信息(缓存限制:1000)
2017-09-29 08:32:57 INFO SpringCamelContext:3039 - 启用AllowUseOriginalMessage。如果访问原始邮件 不需要,然后建议关闭此选项 提高绩效。
2017-09-29 08:32:57 INFO SpringCamelContext:3049 - StreamCaching未使用。如果使用流,则建议启用流 缓存。详情请见 http://camel.apache.org/stream-caching.html
2017-09-29 08:32:57 INFO SpringCamelContext:3570 - 路由:ShellRoute开始使用:Endpoint [direct:// start]
2017-09-29 08:32:57 INFO SpringCamelContext:2840 - 总计1条路线,其中1条路线已启动。
2017-09-29 08:32:57 INFO SpringCamelContext:2841 - Apache Camel 2.17.2(CamelContext:camel-1)在0.667秒内启动
2017-09-29 08:32:57 INFO SupportMain:57 - 在4.963秒内启动SupportMain(JVM运行6.767)
2017-09-29 08:32:57 INFO AnnotationConfigApplicationContext:982 - 结束 org.springframework.context.annotation.AnnotationConfigApplicationContext@776aec5c: 启动日期[Fri Sep 29 08:32:53 EDT 2017];上下文层次结构的根
2017-09-29 08:32:57 INFO AnnotationMBeanExporter:449 - 在关机时取消注册暴露于JMX的bean
2017-09-29 08:32:57 INFO SpringCamelContext:3066 - Apache Camel 2.17.2(CamelContext:camel-1)正在关闭
答案 0 :(得分:0)
在Apache camel中执行shell脚本命令,根据exec组件文档http://camel.apache.org/exec.html
以下示例使用构建文件CamelExecBuildFile.xml执行Apache Ant(仅限Windows),前提是ant.bat位于系统路径中,并且CamelExecBuildFile.xml位于当前目录中。
array(7) {
[0]=> string(29) "Humanity is a wonderful thing"
[1]=> string(26) "maybe tomorrow will be bad"
[2]=> string(26) "this last example sentence"
[3]=> string(71) "I have 495 sentences for like this. Here are the sentence to be deleted"
[4]=> string(0) ""
[5]=> string(0) ""
[6]=> string(4) " "
}
同样如此
from("direct:exec").to("exec:ant.bat?args=-f CamelExecBuildFile.xml")
答案 1 :(得分:0)
直接端点提供路由的同步调用。因此,您必须调用脚本执行的路由。 看看这个调用路由的答案。 Apache Camel : "direct:start" endpoint - what does it mean ?
如果您希望它在启动时只执行一次,您可以替换
from("direct:exec")
类似
from("timer://runOnce?repeatCount=1&delay=5000")
Apache Camel - Triggering a task on startup to run only once
中的相关答案