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