You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Tim83 <ti...@roots.be> on 2009/06/03 14:33:44 UTC
Using camel to send and alter MapMessage to a JMS queue
Hi all,
I'm having some troubles sending a MapMessage to a activemq queue using
camel 1.6.
basicly what I'm trying to achieve is
I have an incoming map message, that first needs to go to service A, then to
service B (optional).
Once the message has been processed by service A, some fields in the map
message need to be changed, in order for service B to handle it properly.
I've tried to configure this using the following XML, however I cannot get
it to create the correct map message containing the correct information to
send it to service B.
The incoming message contains
{source=c:\somefile.txt, to=c:\somefile2.txt, toextra=c:\somefile3.txt}
However for service B the map should become
{source=c:\somefile2.txt, to=c:\somefile3.txt}
Is it possible to do this with camel using the xml config? Because I can't
seem to find out how? :(
<camel:route>
<camel:from uri="activemq:queue:incoming" />
<camel:pipeline>
<camel:to uri="activemq:queue:service.A" />
<camel:choice>
<camel:when>
<camel:el>${in.body["somefield"] == "true"}</camel:el>
<camel:setBody>
<camel:el>what to put here?</camel:el>
</camel:setBody>
<camel:to uri="activemq:queue:service.B"/>
</camel:when>
</camel:choice>
</camel:pipeline>
</camel:route>
Thanks,
Tim
--
View this message in context: http://www.nabble.com/Using-camel-to-send-and-alter-MapMessage-to-a-JMS-queue-tp23850609p23850609.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Using camel to send and alter MapMessage to a JMS queue
Posted by Tim83 <ti...@roots.be>.
Thanks for the hint!
I managed to get it working now.
I made a beanshell processor that can be used as a bean in with Spring XML
The xml config
<bean id="messageProcessor" class="processor.BeanShellProcessor">
<property name="expression">
<value>
in.put("from", in.get("to"));
in.put("to", in.get("toPdf"));
</value>
</property>
</bean>
The java code
import java.util.HashMap;
import org.apache.bsf.BSFManager;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
public class BeanShellProcessor implements Processor {
private String expression;
public void process(Exchange ex) throws Exception {
BSFManager manager = new BSFManager();
manager.declareBean("in", ex.getIn().getBody(), HashMap.class);
manager.exec("beanshell", "myScript.bsh", 0, 0, this.getExpression());
}
public String getExpression() {
return expression;
}
public void setExpression(String expression) {
this.expression = expression;
}
}
Camel config
<camel:route>
<camel:from uri="activemq:queue:incoming" />
<camel:pipeline>
<camel:to uri="activemq:queue:service.A" />
<camel:choice>
<camel:when>
<camel:el>${in.body["somefield"] == "true"}</camel:el>
<camel:process ref="messageProcessor" />
<camel:to uri="activemq:queue:service.B"/>
</camel:when>
</camel:choice>
</camel:pipeline>
</camel:route>
Tim
--
View this message in context: http://www.nabble.com/Using-camel-to-send-and-alter-MapMessage-to-a-JMS-queue-tp23850609p23865923.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Using camel to send and alter MapMessage to a JMS queue
Posted by Willem Jiang <wi...@gmail.com>.
I don't find a way to manipulate the MapMessage with Spring XML file.
But you can leverage the Processor to get back the control :)
<camel:route>
<camel:from uri="activemq:queue:incoming" />
<camel:pipeline>
<camel:to uri="activemq:queue:service.A" />
<camel:choice>
<camel:when>
<camel:el>${in.body["somefield"] == "true"}</camel:el>
<camel:process ref="changeMessageBody"/>
<camel:to uri="activemq:queue:service.B"/>
</camel:when>
</camel:choice>
</camel:pipeline>
</camel:route>
<bean id="changeMessageBody" class="MyProcessor"/>
public class MyProcessor implements Processor {
public void process(Exchange exchange) throws Exception {
Map map = (Map) exchange.getIn().getbody();
// do what you want on this map
// set the map to the exchange
exchange.getOut().setBody(map);
}
}
Willem
Tim83 wrote:
> Hi all,
>
> I'm having some troubles sending a MapMessage to a activemq queue using
> camel 1.6.
>
> basicly what I'm trying to achieve is
>
> I have an incoming map message, that first needs to go to service A, then to
> service B (optional).
> Once the message has been processed by service A, some fields in the map
> message need to be changed, in order for service B to handle it properly.
>
> I've tried to configure this using the following XML, however I cannot get
> it to create the correct map message containing the correct information to
> send it to service B.
>
> The incoming message contains
> {source=c:\somefile.txt, to=c:\somefile2.txt, toextra=c:\somefile3.txt}
>
> However for service B the map should become
> {source=c:\somefile2.txt, to=c:\somefile3.txt}
>
> Is it possible to do this with camel using the xml config? Because I can't
> seem to find out how? :(
>
> <camel:route>
> <camel:from uri="activemq:queue:incoming" />
> <camel:pipeline>
> <camel:to uri="activemq:queue:service.A" />
> <camel:choice>
> <camel:when>
> <camel:el>${in.body["somefield"] == "true"}</camel:el>
> <camel:setBody>
> <camel:el>what to put here?</camel:el>
> </camel:setBody>
> <camel:to uri="activemq:queue:service.B"/>
> </camel:when>
> </camel:choice>
> </camel:pipeline>
> </camel:route>
>
> Thanks,
>
> Tim