How to detect a damaged / restored JMS connection in Apache Camel?

We are building an integration project using Apache Camel (Camel 2.10.3, Java DSL).

We have a route that retrieves data from a database (allows calling IN_DB), performs some logic and inserts into another database (OUT_DB) once a day, and another route that subscribes to the JMS topic for XML data does some logic and inserts it into the same database (OUT_DB) during the day.

The requirement is that when the connection on the JMS topic for any reason goes for any reason, we continue to try to reconnect indefinitely, and as soon as the reconnection is successful, we need to return to the database (IN_DB) and do another load to fill in the gap where the topic was omitted.

My question is, how can we make this logic ("I was connected and then disconnected, and now I am connected again") in Camel? What happens to a route that starts with a topic consumer, when the topic drops, does the route just stop? Or will he throw an error message in the error queue? Should I write my own handler to track the connection to the topic, or Camel will automatically connect when the topic returns and sets a message header, or set some context variable to indicate that "I was connected, then I disconnected and now I am connected again "did the script happen? I am happy to build route logic around a database load call. I just can't figure out how to best “detect” in Camel that this scenario happened.

Any suggestions that are very much appreciated.

+7
java apache-camel jms
source share
1 answer

As for reconnecting to your queue, it depends on which JMS broker you are using. If you use ActiveMQ, you can configure the way to reconnect it through the URI so that it can try to reconnect to another broker, connect to the same broker after a timeout, etc. Documents for him.

To find out when the connection was unsuccessful, the easiest way for the program to just use persistent queues instead. However, believing that this is not possible, I think you have two options.

To find out when it works again, I think you’re stuck in posting a message on a specific topic and watching messages from that topic on a different route. When you read a message on this topic, you know that the broker has returned so that you can reload your data from the database.

or 2. You can post regular listening messages in your JMS topic. If you stop receiving them, you know that the broker has gone down. After you start receiving them again, you know that this is a backup, and you need to reload the data from the database.

+1
source share

All Articles