0

Bit of a Camel newbie but here goes.

I have the following route:

    from("activemq:queue:outputQueue").inputType(HelloWorld.class)
    .to("log:stream")
    .marshal().json(JsonLibrary.Jackson, HelloWorld.class)
    .to("http:localhost:5000/messageForYouSir?bridgeEndpoint=true");

This retrieves messages from the queue and sends them to the HTTP endpoint as JSON. Fine.

But what if there is an error? Say a HTTP error code of 400? Then I want the message to stay on the queue. I have tried looking into not acknowledging the message, but have not been able to make it work.

Also I have made an Exception handler

    onException(HttpOperationFailedException.class)
    .handled(false)
    .setBody().constant("Vi fekk ein feil");

But still the messages are gone from the queue. Is there some magic spell that can make Camel not acknowledge the messages when there is some error?

  • Not ACKing the message is the way to go. Did you have a look at [this question already?](https://stackoverflow.com/questions/13498652/camel-jms-client-acknowledge-mode) – ShellDragon Sep 26 '19 at 07:39
  • Yeah, I did. But doesn't seem to work. Tried the URL activemq:queue:outputQueue?acknowledgementModeName=CLIENT_ACKNOWLEDGE but the queue is emptied. – Torvald Baade Bringsvor Sep 27 '19 at 08:35

1 Answers1

0

You have to consume transacted from the queue to be able to do a rollback. This is configured on the connection configuration to the broker.

Take a look at the Camel JMS docs (the ActiveMQ component extends the JMS component), especially the sections about cache levels and transacted consumption.

The most simple setup is using broker transactions by simply set transacted = true and lazyCreateTransactionManager = false on the JmsConfiguration. This way no Spring TX manager is required.

If transacted consumption is in place and the HTTP server returns an error (basically if an Exception occurs in the Camel Route), Camel does automatically a rollback (if you don't catch the error).

burki
  • 6,741
  • 1
  • 15
  • 31