4

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}}&amp;subject={{errormail.subject}}&amp;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&amp;connectionTimeout=5000
kazanaki
  • 7,988
  • 8
  • 52
  • 79
  • Setup a localhost SMTP spool to relay onto the main internal server? – Steve-o Aug 22 '11 at 09:25
  • @Steve-o Ι do not have access on production. I can only send to IT services .war files and they deploy them. I cannot send them anything else. – kazanaki Aug 23 '11 at 12:52

1 Answers1

1

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

Claus Ibsen
  • 56,060
  • 7
  • 50
  • 65
  • Ok.But shouldn't the connectionTimout work? Now it blocks forever. Also if I use wiretap and the mail server is down, an exception will be thrown and the errorhandler routing will kick again leading into an endless loop. Correct? – kazanaki Aug 18 '11 at 12:59
  • The error handler will not kick in again if you are doing error handling. This has been further improved in Camel 2.8. If a 2nd exception occurs a wrapped exception is set with a descriptive error message. – Claus Ibsen Aug 19 '11 at 06:40
  • Also you option is wrong for connection timeout, you need to use the & character. debugMode=true;connectionTimeout=5000 should be debugMode=true&connectionTimeout=5000 – Claus Ibsen Aug 19 '11 at 06:41