1 Reply Latest reply on Sep 3, 2012 6:16 AM by davsclaus

    aggregation failed

    vasuk

      Hi All

       

       

       

      i have to aggregate two XML files which are converted from csv format successfuly ,available at different  times.

      I have to aggregate both xml file to single xml file.

      But I am facing the problem in aggregation 

       

      here i am providing my code and error details ,

       

      ROUTING

      public void configure() {

                                        try {

                                                  DataFormat bindy = new BindyCsvDataFormat("com.softedge.dto");

                                                  DataFormat bindy1 = new BindyCsvDataFormat("com.softedge.dto1");

                                                        from("file://TEST?fileName=order.csv&noop=true").

                                                        unmarshal(bindy).

                                                        marshal().

                                                        xstream().

                                                        to("file://TESTOUT?fileName=order.xml");

                                                        from("file://TEST?fileName=order_line.csv&noop=true").

                                                        unmarshal(bindy1).

                                                        marshal().

                                                        xstream().

                                                        to("file://TESTOUT?fileName=orderLine.xml");

                                                        Thread.sleep(100);                                                                               

      from("file://TESTOUT?idempotent=true?CamelBatchSize(2)noop=true")

                                                        .delayer(2000)     

                                                        .doTry()

                                                        .aggregate(body(),new MyAggregationStrategy())

                                                            .completionTimeout(3000)

                                                          // .batchSize(2)                                                                               

      .log("aggregation test")

                                                        .to("file://TESTOUTA?fileName=aggregate.xml");

                                                         

       

      The out put file should contain the data from Order.xml, OrderLine.xml

         

       

      Order.xml headers are

       

      Orders     Order_num     Cust_Num     Orderd     Shipped     Promised     Carrier     Terms     PO

       

      OrderLine.xml headers are

       

      Line     Order_num     Line_num     Item_num     Price     Qty     Discount     Extended_price     BackOrder

       

       

       

      Aggregation strategy

      public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {

                if (oldExchange == null) {

                return newExchange;

            }

         

        Message newIn = newExchange.getIn();

                String oldBody = oldExchange.getIn().getBody(String.class);

                String newBody = newIn.getBody(String.class);

                newIn.setBody("");

                return newExchange;

         }

       

      ERROR Detailes

       

       

      ShutdownTask] DefaultShutdownStrategy    INFO  Waiting as there are still 2 inflight and pending exchanges to complete, timeout in 299 seconds.

      DefaultShutdownStrategy        INFO  Waiting as there are still 2 inflight and pending exchanges to complete, timeout in 298 seconds.

      AggregateProcessor             WARN  Error processing aggregated exchange. Exchange[null]. Caused by: org.apache.camel.component.file.GenericFileOperationFailedException - Cannot store file: TESTOUTA\aggregate.xml

      Cannot store file: TESTOUTA\aggregate.xml

       

      The Output xml is in below format

       

      aggregation.xml

      format

       

      Orders     

      Order_num     

               Line     

               Order_num     

               Line_num     

               Item_num     

               Price     

               Qty     

               Discount     

               Extended_price     

               BackOrder

      Cust_Num     

      Orderd     

      Shipped     

      Promised     Carrier     

      Terms     

      PO

       

       

      Plese help me, very urgent

        • 1. Re: aggregation failed
          davsclaus

          You need to specify a correlation expression to the aggregator, so it knows what belongs together.

           

          You use body() which is the message body. That is not a good correlation expression, as this will only be able to aggregate together when the message body is equals.

           

          You need to use something that tells that these 2 files should be aggregated together.

          Is there something in the files itself that says I belong together with you?

           

          If everything just have to be correlated, then you can use constant(true) instead. Then the 2 files will be aggregated always.

           

          I suggest to read more about the aggregate EIP how it works

          http://camel.apache.org/aggregator2

           

          And if you have a copy of the Camel in Action book, then read chapter 8, section 8.2, that has a comprehensive coverage of this pattern.