如果没有从 FTP 中提取文件,则发送电子邮件通知 [英] Send an email notification if no files pulled from FTP

查看:32
本文介绍了如果没有从 FTP 中提取文件,则发送电子邮件通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在通过 Spring 使用 Camel 将文件从 FTP 拉到本地磁盘,然后处理它们.我想在路由执行但没有找到任何要拉取的文件时收到警报.有没有办法用骆驼来做到这一点?

I've been using Camel via Spring to pull files from an FTP to the local disk and then processing them. I'd like to be alerted when the route executes but doesn't find any files to pull. Is there a way to do this with stock camel?

如果没有;我想做的是以自定义验证器"的形式实现一个中间人.然后我会从 camel-ftp 组件路由到自定义验证器,然后它可以进行一些检查,如果需要发送通知,并将文件路由到要写入文件系统的文件组件.

If not; what I was thinking of doing was implementing a middle man in the form of a custom "validator". I'd then route from the camel-ftp component to the custom validator, then it could do some checks, send out notifications if needed, and route the file to the file component to be written to the filesystem.

我尝试添加这个中间人,似乎如果没有找到 FTP 文件,它甚至不会通知中间人.

I experimented with adding this middle-man and it seems that if no FTP files are found it won't even notify the middle-man.

推荐答案

您可以使用该选项

sendEmptyMessageWhenIdle=true

如文档所述(因为 ftp 组件扩展了文件组件并继承了其选项):

As documented at (as the ftp component extends the file component and inheirts its options):

http://camel.apache.org/file2

当使用 sendEmptyMessageWhenIdle 时,如果没有要轮询的 ftp 文件,则会发送一条空消息.

When using sendEmptyMessageWhenIdle then an empty message is sent when there is no ftp files to poll.

然后您可以使用过滤器或基于内容的路由器来检测空文件,然后发送电子邮件.

You can then use a filter or content based router to detect the empty file and then send the email.

此外,您可以考虑将延迟选项设置为更高的值,这样您就不会尝试如此频繁地轮询,因为默认延迟为 500 毫秒.

Also you may consider setting the delay option to a higher value so you wont try to poll so frequently as by default the delay is 500 ms.

delay=10s

例如改为每 10 秒轮询一次.

For example to poll every 10th second instead.

这篇关于如果没有从 FTP 中提取文件,则发送电子邮件通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆