Search code examples
hashmapapache-camelsplitter

can the Splitter EIP split a HashMap or does it have to be a List


I am trying to use the Camel Splitter EIP to split a Map, it doesn't appear to be working and doesn't split a Map. Unless, I'm missing something, ... if this is possible please suggest how.

thank you!!!

Splitting a Map with Camel EIP Splitter.

<process id="getassetlisting" ref="getAssetListing" />
<split id="as2"
    strategyRef="tsAggregationStrategy" streaming="true">
    <simple>${body}</simple>
    <log id="sl2" loggingLevel="INFO" message="Split Line ${body}"/>
</split>

GetAssetListing snippit

public void process(Exchange exchange) throws Exception {

    log.info("Get Asset Listing :: Start");

    custkey = (String)exchange.getIn().getHeader("CUSTKEY");
    log.info("GetAssetListing - CUSTKEY: " + custkey);
    queryRecordToDB(custkey);

    for(Map.Entry m:assetMap.entrySet()){    
       log.info("Key: " + m.getKey() + " Value: " + m.getValue());    
    }
    exchange.getIn().setBody(assetMap);

    log.info("Get Asset Listing :: finish");
   }

Expected: to split the input exchange that is a Map

Inbound to Splitter {BC104_Expander=05d52eb9-6d45-4683-bff2-e079d1d2f745, BC105_Steam_Turbine=1ddeae49-07ab-4872-817d-ba1dc1528fa2, DCM101A_Motor=6eea4f40-9114-491d-b2fb-34f7e9b122de, BCG901_Gearbox=cd46fc06-dc08-42c7-a73e-839d3b27d683, BCM102_Motor=652e4041-3c2b-410a-8ba0-12a2a53ec730, BC101_Compressor=50480a32-cd65-4b93-94f8-4ba50cf6dec5, DC102_Expander=cd413f1e-816f-466d-a706-b87ead050bac, BC901_Steam_Turbine=b4acecbb-fac1-4a99-ab95-24e1bc7f4286, DC101A_Compressor=bbd0a7d7-cb11-4a64-9168-b13ece4b215d, DCM101B_Motor=12819b1c-8dec-49e6-82cd-72e0de36331f, BCM901_Generator=96de09f5-6dac-458f-bcaa-6d67a340e731, BCM101_Motor=6cf41883-36c1-4eca-8325-54588982bdc8, DC901_Steam_Turbine=27f68800-e9d2-4f33-b4e5-9d2031eaa60b, BCG101_Gearbox=49366bcc-bb6a-426f-8c5c-6d65d675ac90, DC101B_Compressor=21a60cce-094d-4844-b448-e9a955de418f, BC102_Compressor=49380230-99eb-4fee-a9a3-e187e4c658ee, DCG901_Gearbox=d015e136-1110-4b6a-a9d2-48dd2ebc8c81, BCG102_Gearbox=f4402fb9-a638-46e1-93d3-bcb927c44ee4}

Expected output from Split

BC104_Expander=05d52eb9-6d45-4683-bff2-e079d1d2f745

BC105_Steam_Turbine=1ddeae49-07ab-4872-817d-ba1dc1528fa2

DCM101A_Motor=6eea4f40-9114-491d-b2fb-34f7e9b122de

BCG901_Gearbox=cd46fc06-dc08-42c7-a73e-839d3b27d683

BCM102_Motor=652e4041-3c2b-410a-8ba0-12a2a53ec730

BC101_Compressor=50480a32-cd65-4b93-94f8-4ba50cf6dec5

DC102_Expander=cd413f1e-816f-466d-a706-b87ead050bac BC901_Steam_Turbine=b4acecbb-fac1-4a99-ab95-24e1bc7f4286 DC101A_Compressor=bbd0a7d7-cb11-4a64-9168-b13ece4b215d DCM101B_Motor=12819b1c-8dec-49e6-82cd-72e0de36331f BCM901_Generator=96de09f5-6dac-458f-bcaa-6d67a340e731 BCM101_Motor=6cf41883-36c1-4eca-8325-54588982bdc8 DC901_Steam_Turbine=27f68800-e9d2-4f33-b4e5-9d2031eaa60b BCG101_Gearbox=49366bcc-bb6a-426f-8c5c-6d65d675ac90 DC101B_Compressor=21a60cce-094d-4844-b448-e9a955de418f BC102_Compressor=49380230-99eb-4fee-a9a3-e187e4c658ee DCG901_Gearbox=d015e136-1110-4b6a-a9d2-48dd2ebc8c81 BCG102_Gearbox=f4402fb9-a638-46e1-93d3-bcb927c44ee4


Solution

  • You can split with Camel whatever you want :-)

    To be honest, I never tried it with a Map, but if it is not supported out of the box, you can implement a Bean to do it the way you want.

    In the Camel route you simply say

    .split().method("mySplitterBean", "splitBody")
    

    Your implementation

    public class MySplitterBean {
        public Map<String, String> splitBody(String body) {
        .... your splitting logic
        }
    }