apache camel 相关配置_使用Apache Camel文件组件实现自定义流程策略

这篇博客讨论了如何在Apache Camel中配置文件组件,以根据`header.processorName`将文件路由到不同的sedas,并自定义处理策略。作者遇到了配置文件端点的问题,特别是关于目录设置和动态日期的问题,寻求解决方案。
摘要由CSDN通过智能技术生成

迄今的尝试 h2>

我有以下启动处理的路由(名称模糊处理):

@Override

public void configure() throws Exception

{

getContext().addEndpoint("processShare", createProcessShareEndpoint());

from("processShare")

.process(new InputFileRouter())

.choice()

.when()

.simple("${header.processorName} == '" + InputFileType.TYPE1 + "'")

.to("seda://type1?size=1")

.when()

.simple("${header.processorName} == '" + InputFileType.TYPE2 + "'")

.to("seda://type2?size=1")

.when()

.simple("${header.processorName} == '" + InputFileType.TYPE3 + "'")

.to("seda://type3?size=1")

.when()

.simple("${header.processorName} == '" + InputFileType.TYPE4 + "'")

.to("seda://type4?size=1")

.when()

.simple("${header.processorName} == '" + InputFileType.TYPE5 + "'")

.to("seda://type5?size=1")

.when()

.simple("${header.processorName} == '" + InputFileType.TYPE6 + "'")

.to("seda://type6?size=1")

.when()

.simple("${header.processorName} == '" + InputFileType.TYPE7 + "'")

.to("seda://type7?size=1")

.otherwise()

.log(LoggingLevel.FATAL, "Unknown file type encountered during processing! --> ${body}");

}点击

我的问题是如何配置文件端点。我目前正在尝试以编程方式配置端点而没有太多运气。迄今为止,我在骆驼方面的经验一直主要使用Spring DSL而不是Java DSL。

我沿着尝试实例化FileEndpoint对象的路线走下去,但是无论何时构建路线,我都会遇到一个错误,指出文件属性为空。我相信这是因为我应该创建一个FileComponent而不是一个端点。我没有使用uri创建端点,因为我无法使用uri在目录名称中指定动态日期。

private FileEndpoint createProcessShareEndpoint() throws ConfigurationException

{

FileEndpoint endpoint = new FileEndpoint();

//Custom directory "ready to process" implementation.

endpoint.setProcessStrategy(getContext().getRegistry().lookup(

"inputFileProcessStrategy", MyFileInputProcessStrategy.class));

try

{

//Controls the number of files returned per directory poll.

endpoint.setMaxMessagesPerPoll(Integer.parseInt(

PropertiesUtil.getProperty(

AdapterConstants.OUTDIR_MAXFILES, "1")));

}

catch (NumberFormatException e)

{

throw new ConfigurationException(String.format(

"Property %s is required to be an integer.",

AdapterConstants.OUTDIR_MAXFILES), e);

}

Map consumerPropertiesMap = new HashMap();

//Controls the delay between directory polls.

consumerPropertiesMap.put("delay", PropertiesUtil.getProperty(

AdapterConstants.OUTDIR_POLLING_MILLIS));

//Controls which files are included in directory polls.

//Regex that matches file extensions (eg. {SOME_FILE}.flag)

consumerPropertiesMap.put("include", "^.*(." + PropertiesUtil.getProperty(

AdapterConstants.OUTDIR_FLAGFILE_EXTENSION, "flag") + ")");

endpoint.setConsumerProperties(consumerPropertiesMap);

GenericFileConfiguration configuration = new GenericFileConfiguration();

//Controls the directory to be polled by the endpoint.

if(CommandLineOptions.getInstance().getInputDirectory() != null)

{

configuration.setDirectory(CommandLineOptions.getInstance().getInputDirectory());

}

else

{

SimpleDateFormat dateFormat = new SimpleDateFormat(PropertiesUtil.getProperty(AdapterConstants.OUTDIR_DATE_FORMAT, "MM-dd-yyyy"));

configuration.setDirectory(

PropertiesUtil.getProperty(AdapterConstants.OUTDIR_ROOT) + "\\" +

dateFormat.format(new Date()));

}

endpoint.setConfiguration(configuration);

return endpoint;点击

问题 H2>

在这种情况下,实施GenericFileProcessingStrategy是否正确?如果是这样,那么这里有一个例子吗?我已经浏览了骆驼文件单元测试,并没有看到任何跳出我的东西。

我在配置端点时做了什么错误?我觉得清理这个混乱的答案与问题3紧密相关。

您可以在轮询和日期更改时将文件终结点配置为滚动日期文件夹

一如既往感谢您的帮助。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值