1

I'm having a problem with handling JMS topic message using Apache Camel. Here's a route (Spring context fragment) I use to read and handle the message:

 <camel:route id="refreshParameters" autoStartup="true" >
        <camel:from uri="activemq:topic:{{refreshParameters.inputTopic}}" />
        <camel:log message="handling refresh topic"></camel:log>
        <camel:log message="${body}" />
        <camel:unmarshal ref="RefreshParametersRequest" />
        <camel:bean ref="RefreshParametersHandler" method="refreshParameters" />
    </camel:route>

The route runs multiple times (about 60) for each message. From my undestanding it should be executed only once. Here's a log piece:

thread #243 - JmsConsumer[refreshterm]:) handling refresh terminal topic
thread #221 - JmsConsumer[refreshterm]:) handling refresh terminal topic
thread #237 - JmsConsumer[refreshterm]:) handling refresh terminal topic
thread #221 - JmsConsumer[refreshterm]:) {"uId":"44298b83-9a88-4b80-9b16-e60d1cfeaf9a","tid":"12340003","iid":"TMS0","m":false}
thread #237 - JmsConsumer[refreshterm]:) {"uId":"44298b83-9a88-4b80-9b16-e60d1cfeaf9a","tid":"12340003","iid":"TMS0","m":false}
thread #246 - JmsConsumer[refreshterm]:) handling refresh terminal topic
thread #246 - JmsConsumer[refreshterm]:) {"uId":"44298b83-9a88-4b80-9b16-e60d1cfeaf9a","tid":"12340003","iid":"TMS0","m":false}
thread #243 - JmsConsumer[refreshterm]:) {"uId":"44298b83-9a88-4b80-9b16-e60d1cfeaf9a","tid":"12340003","iid":"TMS0","m":false}
thread #248 - JmsConsumer[refreshterm]:) handling refresh terminal topic
thread #242 - JmsConsumer[refreshterm]:) handling refresh terminal topic
thread #248 - JmsConsumer[refreshterm]:) {"uId":"44298b83-9a88-4b80-9b16-e60d1cfeaf9a","tid":"12340003","iid":"TMS0","m":false}
thread #242 - JmsConsumer[refreshterm]:) {"uId":"44298b83-9a88-4b80-9b16-e60d1cfeaf9a","tid":"12340003","iid":"TMS0","m":false}
thread #239 - JmsConsumer[refreshterm]:) handling refresh terminal topic
thread #240 - JmsConsumer[refreshterm]:) handling refresh terminal topic
thread #239 - JmsConsumer[refreshterm]:) {"uId":"44298b83-9a88-4b80-9b16-e60d1cfeaf9a","tid":"12340003","iid":"TMS0","m":false}
thread #226 - JmsConsumer[refreshterm]:) handling refresh terminal topic
thread #249 - JmsConsumer[refreshterm]:) handling refresh terminal topic
thread #240 - JmsConsumer[refreshterm]:) {"uId":"44298b83-9a88-4b80-9b16-e60d1cfeaf9a","tid":"12340003","iid":"TMS0","m":false}
thread #226 - JmsConsumer[refreshterm]:) {"uId":"44298b83-9a88-4b80-9b16-e60d1cfeaf9a","tid":"12340003","iid":"TMS0","m":false}
thread #249 - JmsConsumer[refreshterm]:) {"uId":"44298b83-9a88-4b80-9b16-e60d1cfeaf9a","tid":"12340003","iid":"TMS0","m":false}
thread #206 - JmsConsumer[refreshterm]:) handling refresh terminal topic
thread #210 - JmsConsumer[refreshterm]:) handling refresh terminal topic
thread #210 - JmsConsumer[refreshterm]:) {"uId":"44298b83-9a88-4b80-9b16-e60d1cfeaf9a","tid":"12340003","iid":"TMS0","m":false}

Route executions seem to be run asynchronously and not being a result of handling reattempting. Moreover, this route is the only topic's subscriber, but when handling stops the message is still in the topic. Shouldn't it be deleted as there are no more subscibers this message can be delivered to?

  • I found that setting concurrentConsumers property to 1. Makes camel create single consumer for a topic: Nevertheless, I still don't know why other consumers fire when one of them had already received a message. Does that anything to do with JMS server keeping messages in the topic? Is this somehow configurable? – user1511469 Feb 05 '16 at 13:05
  • Yes study JMS and how topic works, each consumer on a topic gets a copy of the message. So this is expected. – Claus Ibsen Feb 05 '16 at 14:54
  • 1
    If you need concurrent consumers for a topic AND you are using ActiveMQ, then you might want to look into [virtual topics](http://activemq.apache.org/virtual-destinations.html). – Ralf Feb 05 '16 at 16:42

0 Answers0