Aldrine Einsteen
Aldrine Einsteen

Reputation: 104

apache-camel put bulk messages into JMS

Am setting up a project where bulk commit of JMS has to be done in a single shot. Using the transaction for restarting the message processing, so need thoughts on how to push "x" number of messages onto a JMS Queue and do JMS commit.

What am currently doing is creating a JMS message which a long string appended with the message which I wish to commit in one shot. Then use a Splitter to split the message into multiple in another route. Finally, use another route to send the messages onto JMS (as a bulk commit).

    <route>
        <from uri="file:sample"/>
        <split streaming="true">
            <tokenize token="\n"/>
            <to uri="activemq:queue:dest"/>
        </split>
    </route>

I wish to construct a route that controls when the JMS commit is issued.

The use case is am trying to read a message from Queue A and create many messages (let that number be "x"). And push them to Queue B. However, I wish to do a bulk commit (or batch commit) like DB. Am trying to be efficient not to create connections to JMS and do individual commits.

Upvotes: 1

Views: 1138

Answers (1)

burki
burki

Reputation: 7035

I don't fully see your problem. Perhaps it is just a matter of what error handling to use.

Setup: You have a Camel route with a transacted JMS consumer and in this route you send multiple messages to one or different queues.

Good case: The route is successfully completed and all JMS messages are delivered.

Error case: If your route encounters an error, let's say in the middle of processing, some JMS messages are already "sent", some are not.

In this case no messages are sent at all because Camel does a rollback and the already "sent" JMS messages are not really sent or, to be more precise, they are not yet committed and they will not get committed.

Important detail: Camel must not handle the error. If it does, the error is not propagated to the broker and therefore the consumed message is committed and so is the JMS transaction.

Upvotes: 2

Related Questions