...
A common use case in Camel is to consume messages from a queue and aggregate them before sending the aggregated state to another endpoint. In order to ensure that data is not lost if the system performing the processing fails, it is typically consumed within a transaction from the queue, and once aggregated stored in a persistent AggregationRepository
, such as the one found in Camel the JDBC Component.
The behavior of the aggregator pattern involves fetching data from the AggregationRepository
before an incoming message is aggregated, and writing back the result afterwards. By nature, the reads and writes take progressively longer as the number of aggregated artifacts increases. A rough example of this using arbitrary time units that demonstrates the impact of this is as follows:
...
In contrast, consumption performance using the SJMS Batch component is linear. Each message is consumed and aggregated using an AggregationStrategy
before the next one is fetched. As all of the consumption an and aggregation is performed in a single JMS transaction , no external storage is required to persist the intermediate state , and - this avoids the read and write costs described above. In practice, this yields multiple orders of magnitude higher throughput.
...
Unlike using a regular aggregator, there is no facility for an aggregation condition, meaning that it is not possible to batch consume into multiple groups of messages at the same time. All consumed messages are aggregated together into a single batch. To get around this, a common design approach is to first sort the different groups of messages to be aggregated onto different queues, and batch consume from each one separately.
Multiple JMS consumer support is available which allows you to consume in parallel using the one route, and at the same time use facilities like JMS message groups to group related messages.
...
Code Block | ||
---|---|---|
| ||
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-sjms</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency> |
SJMS Batch is a subcomponent of SJMS, and resides in the same library.
URI format
Code Block |
---|
sjms:[queue:]destinationName[?options] |
...
Topic consumption is not supported, as there is no advantage to using batch consumption within that context. Topic messages are usually non-persistent, and loss is acceptable. If consumed within a transaction that fails, a topic message will likely not be redelivered by the broker. A plain SJMS consumer endpoint can be used in conjunction with a regular non-persistence backed aggregator in this scenario.
Component Options and Configurations
...
Div | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||||||||||||
|
The completionSize
endpoint attribute is used in conjunction with completionTimeout
, where the first condition to be met will cause the aggregated Exchange
to be emitted down the route.
...