added myaggregator and modified classes

This commit is contained in:
2021-11-17 11:51:55 +01:00
parent cd861c7b87
commit 8b72c79475
6 changed files with 96 additions and 11 deletions

View File

@@ -45,19 +45,20 @@ public class Main {
public void configure() throws Exception {
from("direct:start")
.setBody(constant("SELECT * FROM material LIMIT 10"))
.setBody(constant("SELECT * FROM material"))
.to("jdbc:source")
.split(body())
.to("activemq:queue:material");
from("direct:getPackages")
.setHeader("material_id", simple("${body[id]}"))
.setBody(simple("SELECT * FROM package WHERE material_id = :?material_id"))
.to("jdbc:source?useHeadersAsParameters=true");
from("activemq:queue:material")
.split(body())
//.bean(myFunctions, "getId")
.setHeader("id", simple("${body[id]}"))
.setBody(constant("SELECT * FROM package WHERE material_id = :?id"))
.to("jdbc:source?useHeadersAsParameters=true")
.to("activemq:queue:materialPackage");
//.to("log:?level=INFO&showBody=true");
.enrich("direct:getPackages",new MyAggregator())
.to("activemq:queue:materialPackage")
.to("log:?level=INFO&showBody=true");
}
});

View File

@@ -3,15 +3,26 @@ package com.release11;
import org.apache.camel.AggregationStrategy;
import org.apache.camel.Exchange;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class MyAggregator implements AggregationStrategy {
@Override
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
String oldEx = oldExchange.getIn().getBody().toString();
HashMap oldEx = (HashMap) oldExchange.getIn().getBody();
System.out.println(oldEx);
String newEx = newExchange.getIn().getBody().toString();
ArrayList<HashMap> newEx = (ArrayList) newExchange.getIn().getBody();
System.out.println(newEx);
return null;
oldEx.put("packages", newEx);
Exchange result = oldExchange;
result.getIn().setBody(oldEx);
//result.getIn().setBody(body);
System.out.println(result.getIn().getBody());
return result;
}
}