Understanding Apache Camel Dynamic Routing
I have installed a simple dynamic router:
public String slip(String body, @Header(Exchange.SLIP_ENDPOINT) String previous) {
if (previous == null) {
return "mock:a";
}
else if (body.contains("status=2") ) {
return "mock:b";
}
else if (body.contains("status=3") ) {
return "mock:c";
}
// no more so return null
return null;
}
Mock a, b, c - routes with custom processors.
public void process(Exchange exchange) throws Exception {
String str_request = "";
String str_requestNew = "";
str_request = (String) exchange.getIn().getBody();
if(str_request.contains("status=1"))
str_requestNew = "status=2";
}
-
How do I update the message body between routes in my custom cpu via Java DSL. exchange.getOut () setBody (newreq).
-
Do I need to create a new manufacturer and send the message back to the dynamic router? ProducerTemplate template = exchange.getContext (). CreateProducerTemplate (); template.sendBody (myDynamicRouterEndpoint, newreq); or my router will take a new body if it does it using method 1.
Or is there a huge flaw in my logic? :)
source to share
You can do this as described in 1.
It's even easier if you are using a bean component. Then you can have a simple Java method to read and customize the body:
public String doSomething (string body) {}
This will get the body in the parameter and the return value will be the new body. This also makes your bean Camel independent.
source to share