Frage

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
War es hilfreich?

Lösung

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top