How Camel 2.11 batch aggregation works with separate route?

前端 未结 1 480
一个人的身影
一个人的身影 2021-01-14 00:19

First there is a similar unanswered question Joining routes into single aggregator

We have some consumer routes (ftp, file, smb) reading files from remote systems.

相关标签:
1条回答
  • 2021-01-14 01:13

    You almost have it working. Here is the change you need (and after I will explain).

    from("direct:aggregate").id("aggregate")
        .aggregate(property(AGGREGATION_PROPERTY), new BodyInAggregationStrategy())
        .completionSize(property(Exchange.BATCH_SIZE))
        .to("log:result", "mock:result")
    

    The result will be:

    Exchange received, body: A+A+A
    Exchange received, body: B+B
    Exchange received, body: A
    

    Note: You won't receive a result for the "Z" since the batch size is 7.

    To explain - as you have read, the Aggregator is a versatile camel component and the key things to define correctly are:

    • the aggregation expression
    • the completion rule

    Now in your case you are aggregating on a property AGGREGATION_PROPERTY which will be A, B or Z. In addition you are specifying a batch size.

    However you aren't expressing a completionSize() in your route. Instead you were using completionFromBatchConsumer - which does something different (the code states that it looks for a Exchange#BATCH_COMPLETE property), thus the weird results.

    Anyway, .completionSize(Exchange.BATCH_SIZE) will make your test run as desired.

    Good luck further.

    0 讨论(0)
提交回复
热议问题