camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From contactreji <contactr...@gmail.com>
Subject Producer Template // Count mismatch
Date Wed, 06 Jan 2016 11:40:46 GMT
Hi 

I have a code like this

package com.processors

import org.apache.camel.Endpoint
import org.apache.camel.Exchange
import org.apache.camel.ExchangePattern
import org.apache.camel.Processor
import org.apache.camel.impl.DefaultCamelContext

/**
 * Created by Z001NLH on 12/30/2015.
 */
class BatchOutRecordsImpl implements Processor{

    //Static variables section
    static def BATCH_GROUP_KEY = "FRTB_I"
    static def DESTINATION_CAMEL_ENDPOINT =
"seda:AllocationAmountPerShipment" //This should be a valid camel endpoint
    //static def DESTINATION_CAMEL_ENDPOINT = "vm:batchedRecords" //This
should be a valid camel endpoint
    @Override
    void process(Exchange exchange) throws Exception {


        def records=(List<Map&lt;String, Object>>)
exchange.getIn().getBody()
        def camelContext = exchange.getContext()
        def producerTemplate = camelContext.createProducerTemplate()
        def batch= new ArrayList<HashMap&lt;String,Object>>()
        def previousBatchKey=null
        def isLastIteration=false
        def counter=1
        //Looping through resultset
        for(HashMap<String,Objects> record in records)
        {
            isLastIteration=false
            if(counter==records.size()) {
                isLastIteration = true
            }
            def batchKey=record.get(BATCH_GROUP_KEY)

            try{
               
previousBatchKey=batch.get(batch.size()-1).get(BATCH_GROUP_KEY)
            }catch(java.lang.ArrayIndexOutOfBoundsException e)
            {
                println("Batch was Empty / Cleared stage")
                previousBatchKey=batchKey
            }
            if(batchKey==previousBatchKey) {
                batch.add(record)
            }
            if(isLastIteration||(batchKey!=previousBatchKey)) {

                //Sending for processing
                *producerTemplate.sendBody(DESTINATION_CAMEL_ENDPOINT,
ExchangePattern.InOnly, batch)*
                //wiretapping records to folder dumped records
                def freightID=batch.get(batch.size()-1).get("FRTB_I")
               * producerTemplate.sendBodyAndHeader("vm:batchedRecords",
ExchangePattern.InOnly,
batch.toString(),"CamelFileName",freightID.toString())*

                batch.clear()
                if(isLastIteration==false) {
                    batch.add(record)
                }
            }
            counter++
        }
    }
}

I have highlighted 2 producer templates.. Unfortunately I am trying to send
the same body from both templates. But on the other end, the numbers
mismatch. One producer template received 2098 records and other one received
2089.

Any clue of why this happens? The body contains List<HashMaps&lt;k,v>>


Cheers
Reji



-----
Reji Mathews
Sr. Developer - Middleware Integration / SOA ( Open Source - Apache Camel & Jboss Fuse
ESB | Mule ESB )
LinkedIn - http://in.linkedin.com/pub/reji-mathews/31/9a2/40a
Twitter - reji_mathews
--
View this message in context: http://camel.465427.n5.nabble.com/Producer-Template-Count-mismatch-tp5775891.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Mime
View raw message