2

I have an aggregator that is supposed to take all messages with a certain correlation key (in the example below I hardcoded this to 10, because the corresponding Splitter generates 10 messages).

I can see many messages via logging, and all 10 messages generated, but never 10 being received by the aggregator. Here is the code for the aggregator:

@MessageEndpoint
public class MyAggregator {     
   @ReleaseStrategy
   public boolean releaseStrategy( final List< Map< String, String > > msgs )
   {
       System.out.println( "Aggregator.releaseStrategy:  received " + msgs.size() + " messages " );

       if( msgs.size() == 10 ) {
           System.out.println( "releasing the fragments!" );
           return true;
       }           
       return false;
   }

   @CorrelationStrategy
   public String correlationStrategy( final Map< String, String > msg ) 
   {
       return msg.get( "job.oid" );
   }

   @Aggregator( inputChannel = "input", 
                outputChannel = "output"  )
   public Map< String, String > aggregate( final List< Map< String, String > > msgs ) {

        System.out.println( "received all fragments of a job! Number of fragments: " + msgs.size() );

        Map< String, String > msg = new HashMap< String, String >();
        String jobOid = "";
        if( !msgs.isEmpty()) {
            jobOid = msgs.get( 0 ).get( "job.oid" );
        }
        msg.put( "job.oid", jobOid );
        msg.put( "job.numberOfFragments", ""+msgs.size() );
        return msg;
   }
}

Could it be that multiple instances of the aggregator are consuming the messages, so that neither will receive all 10 belonging to one correlation group?

How can I fix this, since the aggregator I am writing is supposed to take ALL correlated messages and produce a new message from this.

  • 1
    Nothing obvious yet. The code looks good. So, you should share more context. Even better something like test-case to play from our side. Plus share, please, the `DEBUG` log for the `org.springframework.integration` to see how your message are traveling. – Artem Bilan Apr 07 '16 at 15:21
  • I uploaded the log output as gist, so that this question doesn't geet cluttered: [DEBUG Log](https://gist.github.com/pelikan400/dc2bda3703dd28d8e6b49464b260f1a4) And I also appended the Generator (aka Splitter) so that the rendevouz between them can be better seen. Everything seems OK, except that when I send 10 messages from Generator to Aggregator they are received somehow partitioned into 8 and 2. – Edmund Bayerle Apr 11 '16 at 08:51
  • Well. you don't say anything about your XD environment structure. Maybe you have there several nodes. So, your messages might be distributed between them, therefore to achiever the requirements with single result after the aggregator, you should consider to use *Persistent Message Store*: http://docs.spring.io/spring-integration/reference/html/system-management-chapter.html#message-store – Artem Bilan Apr 11 '16 at 13:42
  • 1
    I use `bin/xd-singlenode`. Everything runs on one machine. In the `xd-shell` I first upload the modules and then create a stream like this: `stream create --name batchstream2 --definition "batchjob-source | batchjob-fragment-generator | batchjob-fragment-aggregator | log" --deploy` After that, I can see the messages being generated in regular intervals by the source, travelling to the generator which in turn generates messages for the aggregator. – Edmund Bayerle Apr 11 '16 at 14:25
  • 1
    OK. That's great. What is bad that it doesn't become more cleaner, even worse. I really see by your logs that everything is done in the same thread and during the single second. But we really see like the second group is formed and it is when we haven't released that group yet! Would you mind to combine everything in the single XD module (splitting and aggregation) and come back here with results? I'm not sure what's wrong but looks like something cleans the aggregator's `MessageStore` in between message 7 and 8... – Artem Bilan Apr 11 '16 at 14:31

0 Answers0