Java – if the mail server shuts down, the Apache camel SMTP component suspends the entire bus
I think this is a very common situation I have an invoice system managed by Apache camel When something goes wrong, I want to send an email alert to the administrator
After reading camel exception handling, I came up with this: (in 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 applies to my use case When any exception is thrown, an email is sent to the defined address
But to test the corner, I stopped the internal email server to see what happened I want camel to try to send e-mail and stop trying after 5 seconds (as set in the connectiontimout option in the SMPT URL above)
But in fact, the entire camera application will hang! This is simply unacceptable! I can't guarantee that the mail server will rise 100%
Did I miss anything here? Should I completely abandon the idea of email alerts, or does camel need another special option so that it doesn't hang when the mail server is down?
answer
This line
debugMode=true;connectionTimeout=5000
should
debugMode=true&connectionTimeout=5000
Solution
Camel uses the java mail API, so how long it takes to send an email or figure out something is wrong
You can use wiretap to send email asynchronously Then the error handler thread does not seem to block for longer http://camel.apache.org/wire-tap