Warm tip: This article is reproduced from stackoverflow.com, please click
apache-camel java

"Fire then Return" route in Apache Camel

发布于 2020-03-29 21:00:14

We use Apache Camel to trigger some processes within our applications, e.g:

from("quartz2://sometThing/someQueue?cron=0+0+4+?+*+MON-SUN").setBody(constant(""))
    .routeId(this.getClass().getSimpleName())
    .to("jms:some-trigger-queue");

We then have a bunch of processors off the trigger queue to run each job, e.g:

from("jms:some-trigger-queue")
    .processRef("someProcessor");

Some of these processors will in turn write messages to JMS queues. The problem I'm trying to fix is that the processors won't commit the JMS messages to the broker until the entire process is complete. I suspect this is because there is a message in flight on the trigger queue ("jms:some-trigger-queue") and because the processors are using the same context they won't commit until the in flight message is cleared (FYI I have tried forcing new transactions to be created within the processors but had no luck).

So my question is if I only had one processor (or my didn't care about the processors running at the same time) - how could I configure camel to trigger the processor and immediately move on (i.e. to remove the trigger message from being in flight)?

Questioner
BombTodley
Viewed
25
Radu Podea 2020-01-31 18:24

If you want to call the processors and then immediately move on then you can use the Wire Tap EIP (https://camel.apache.org/manual/latest/wireTap-eip.html).

For example:

    from("jms:some-trigger-queue")
            .wireTap("direct:callProcessor");

    from("direct:callProcessor")
            .processRef("someProcessor");

This way the direct:callProcessor route will be executed on a separate thread and jms:some-trigger-queue will continue routing without waiting for a response from direct:callProcessor.