It’s a common question - how to get Apache Camel and the JVM it’s running in to shut down after processing a certain number of messages.
Previously, if you wanted to shut down a Camel app after a certain amount of time, or a certain number of messages, you would need to implement your own logic and possibly an explicit shut down command.
However from Camel 2.19 onwards, if you’re using Spring Boot as a container, there is out-of-the-box support to do this.
Auto shutdown of Camel in Spring Boot - settings
To make Apache Camel shut down after a certain amount of time or messages, any of the following properties to your
To shut down a Camel application after processing a certain number of messages:
To shut down a Camel application after a fixed period of time:
To shut down a Camel application after Camel has been idle for a certain number of seconds (in other words, if it’s not currently processing an Exchange):
This will really help you out if you’re implementing microservices with Camel. These settings mean it’s much easier to use Camel to just process a single file, or run for a short amount of time.
Look out for these messages in the log:
2018-05-29 16:39:06.963 INFO 82642 --- [ main] o.a.camel.spring.boot.RoutesCollector : CamelSpringBoot will terminate after processing 4 messages ... 2018-05-29 16:35:01.674 INFO 60394 --- [otTerminateTask] o.a.camel.spring.boot.RoutesCollector : CamelSpringBoot triggering shutdown of the JVM.
See Camel issue CAMEL-10596.
What do you think? You can use Markdown in your comment.
To write code, indent each line with 4 spaces. Or, to paste a lot of code, you can put it in pastebin.com and share the link in your comment.