如果邮件服务器关闭,Apache Camel smtp 组件将挂起整个总线
我有一个我认为非常常见的场景。我有一个通过 Apache Camel 管理的发票系统。当出现问题时,我希望向管理员发送电子邮件警报。
在阅读了 Camel 异常处理之后,我想到了这个:(在我的 Spring XML 中)
<!-- General retrasmission policy set to 3 times -->
<errorHandler id="deadChannel" type="DeadLetterChannel"
deadLetterUri="direct:invoice-error">
<redeliveryPolicy maximumRedeliveries="2"
redeliveryDelay="1000" backOffMultiplier="2" useExponentialBackOff="true" />
</errorHandler>
<!-- Problematic invoices create email alerts to the administrator -->
<route id="invoices-with-errors">
<from uri="direct:invoice-error" />
<bean ref="emailAlert" method="handleProblematicInvoice" />
<to
uri="smtp://{{errormail.host}}?to={{errormail.to}}&subject={{errormail.subject}}&from={{errormail.from}};debugMode=true;connectionTimeout=5000" />
</route>
这对于我的用例来说OK。当抛出任何异常时,会发送电子邮件 确实到了定义的地址。
但是,为了测试极端情况,我停止了内部电子邮件服务器以查看发生了什么 发生。我预计 Camel 会尝试发送电子邮件,并在 5 秒后停止尝试(如上面 smpt URL 中的 connectionTimout 选项中所设置),
但实际上,整个 Camel 应用程序挂起!这简直让人无法接受! 我不能保证邮件服务器会 100% 正常运行。
我在这里错过了什么吗?我是否应该完全放弃电子邮件警报的想法,或者 Camel 是否需要另一个特殊选项来在邮件服务器关闭时不挂起?
答案
该行
debugMode=true;connectionTimeout=5000
应该是
debugMode=true&connectionTimeout=5000
I have what I think is a very common scenario. I have an invoice system that is managed via Apache Camel. When something goes wrong I would like to have an email alert sent to the administrator.
After reading about Camel exception handling I came up with this: (inside my Spring XML)
<!-- General retrasmission policy set to 3 times -->
<errorHandler id="deadChannel" type="DeadLetterChannel"
deadLetterUri="direct:invoice-error">
<redeliveryPolicy maximumRedeliveries="2"
redeliveryDelay="1000" backOffMultiplier="2" useExponentialBackOff="true" />
</errorHandler>
<!-- Problematic invoices create email alerts to the administrator -->
<route id="invoices-with-errors">
<from uri="direct:invoice-error" />
<bean ref="emailAlert" method="handleProblematicInvoice" />
<to
uri="smtp://{{errormail.host}}?to={{errormail.to}}&subject={{errormail.subject}}&from={{errormail.from}};debugMode=true;connectionTimeout=5000" />
</route>
This works OK for my use case. When any exception is thrown an email is sent
indeed to the defined address.
However in order to test for corner cases I stopped the internal email server to see what
happens. I expected Camel to attempt an email send and stop trying after 5 seconds (as set in the connectionTimout option in the smpt URL above)
In reallity however the WHOLE Camel application hangs! This is simply unacceptable!
I cannot guarantee that the mail server will be up 100%.
Am I missing something here? Should I drop the idea of email alerts altogether or does Camel need another special option for NOT hanging when the mail server is down?
Answer
The line
debugMode=true;connectionTimeout=5000
should be
debugMode=true&connectionTimeout=5000
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Camel 使用 Java Mail API,因此发送电子邮件或发现问题需要多长时间都受到它的支配。
您可以使用wireTap 异步发送电子邮件。那么错误处理线程就不会出现阻塞较长时间的情况
http://camel.apache.org/wire-tap
Camel uses the Java Mail API, and thus is under its mercy how long time it takes to send an email or figure out something is wrong.
You can use the wireTap to async send the email. Then the error handler thread will not appear to block for a longer time
http://camel.apache.org/wire-tap