Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
205 views
in Technique[技术] by (71.8m points)

java - Send an email notification if no files pulled from 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?

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.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use the option

sendEmptyMessageWhenIdle=true

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

http://camel.apache.org/file2

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.

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

For example to poll every 10th second instead.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...