Uploaded image for project: 'FUSE Mediation Router'
  1. FUSE Mediation Router
  2. MR-412

Minor mistake in aggregation documentation for Fuse MR

    XMLWordPrintable

Details

    Description

      Fintan there is a minor issue in the aggregator docu at
      http://fusesource.com/docs/router/2.5/eip/MsgRout-Aggregator.html

      In the code

      public class MyAggregationStrategy implements AggregationStrategy {
          public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
              String oldBody =
                  oldExchange.getIn().getBody(String.class);
              String newBody =
                  newExchange.getIn().getBody(String.class);
              String concatBody = oldBody.concat(newBody);
              // Concatenate old and new.
              oldExchange.getIn().setBody(concatBody);
              // Ignore the message headers!
              // (in a real application, you would probably do
              //  something more sophisticated here).
              return oldExchange;
          }
      }
      

      You should check that oldExchange is null.
      So it should be

      public class MyAggregationStrategy implements AggregationStrategy {
          public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
              if (oldExchange == null) {
                  // first time, the oldExchange is null, so just return newExchange as nothing to merge
                  return newExchange;
              }
      
              String oldBody =
                  oldExchange.getIn().getBody(String.class);
              String newBody =
                  newExchange.getIn().getBody(String.class);
              String concatBody = oldBody.concat(newBody);
              // Concatenate old and new.
              oldExchange.getIn().setBody(concatBody);
              // Ignore the message headers!
              // (in a real application, you would probably do
              //  something more sophisticated here).
              return oldExchange;
          }
      }
      

      Attachments

        Activity

          People

            fbolton@redhat.com Fintan Bolton (Inactive)
            cibsen@redhat.com Claus Ibsen
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: