You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by selezovikj <se...@gmail.com> on 2008/10/21 12:43:38 UTC
Content Based Router
I have a camel route configuration in a camel-server.xml file:
<camelContext id="camel"
xmlns="http://activemq.apache.org/camel/schema/spring">
<route>
<from uri="jms:topic:LoggingTopic"/>
<to uri="bean:msgParser"/>
<to uri="bean:contentRouter"/>
</route>
</camelContext>
In the contentRouter bean I want, when a certain condition is met to set a
header like setHeader("action", "filterA"), which later I can use to perform
routing logic.
while ((strLine = br.readLine()) != null) {
if(messageName.equals(strLine)){
//SET HEADER or DIRECTLY ROUTE TO FILTER BEAN and then to
FINAL BEAN
} else{
//DIRECTLY ROUTE TO FINAL BEAN
}
in.close();
}
I am passing an object to this bean as far as I know. How can I make it
relate to a message on which I can do setHeader ? Later this bean will just
return a message and I will have something like:
<camelContext id="camel"
xmlns="http://activemq.apache.org/camel/schema/spring">
<route>
<from uri="jms:topic:LoggingTopic"/>
<to uri="bean:msgParser"/>
<to uri="bean:contentRouter"/>
</route>
<route>
<from uri="bean:contentRouter"/>
<choice>
<when>
<xpath>$action = 'filterA'</xpath>
<to uri="bean:filter"/>
</when>
<otherwise>
<to uri="bean:final/>
</otherwise>
</choice>
</route>
</camelContext>
--
View this message in context: http://www.nabble.com/Content-Based-Router-tp20087651s22882p20087651.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Content Based Router
Posted by James Strachan <ja...@gmail.com>.
2008/10/21 selezovikj <se...@gmail.com>:
>
> I have a camel route configuration in a camel-server.xml file:
>
> <camelContext id="camel"
> xmlns="http://activemq.apache.org/camel/schema/spring">
> <route>
> <from uri="jms:topic:LoggingTopic"/>
> <to uri="bean:msgParser"/>
> <to uri="bean:contentRouter"/>
> </route>
> </camelContext>
>
> In the contentRouter bean I want, when a certain condition is met to set a
> header like setHeader("action", "filterA"), which later I can use to perform
> routing logic.
>
> while ((strLine = br.readLine()) != null) {
> if(messageName.equals(strLine)){
> //SET HEADER or DIRECTLY ROUTE TO FILTER BEAN and then to
> FINAL BEAN
>
> } else{
>
> //DIRECTLY ROUTE TO FINAL BEAN
> }
> in.close();
> }
>
> I am passing an object to this bean as far as I know. How can I make it
> relate to a message on which I can do setHeader ?
I don't really follow the question - do you wanna try rephrase that sentence?
You can use the Bean Binding so that when your bean is invoked you get
access to whatever in/out headers you want. Or you can just implement
the Processor interface and have the Exchange so you can play around
with headers/properties/payloads etc
http://activemq.apache.org/camel/bean-binding.html
--
James
-------
http://macstrac.blogspot.com/
Open Source Integration
http://fusesource.com/
RE: Content Based Router
Posted by Claus Ibsen <ci...@silverbullet.dk>.
Hi
You can use bean binding to add a 2nd paramter and annotate it as the @Headers
Public void myMethodInBean(@Headers Map headers, Object payload)
The bean binding is quite powerful. And had a rework on the wiki by James:
http://activemq.apache.org/camel/bean-integration.html
See this wiki for the annotations:
http://activemq.apache.org/camel/parameter-binding-annotations.html
Or you can use the Exchange directly: (if not like annotations)
Public void myMethodInBean(Exchange exchange)
Med venlig hilsen
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk
-----Original Message-----
From: selezovikj [mailto:semir.elezovic@gmail.com]
Sent: 21. oktober 2008 12:44
To: camel-user@activemq.apache.org
Subject: Content Based Router
I have a camel route configuration in a camel-server.xml file:
<camelContext id="camel"
xmlns="http://activemq.apache.org/camel/schema/spring">
<route>
<from uri="jms:topic:LoggingTopic"/>
<to uri="bean:msgParser"/>
<to uri="bean:contentRouter"/>
</route>
</camelContext>
In the contentRouter bean I want, when a certain condition is met to set a
header like setHeader("action", "filterA"), which later I can use to perform
routing logic.
while ((strLine = br.readLine()) != null) {
if(messageName.equals(strLine)){
//SET HEADER or DIRECTLY ROUTE TO FILTER BEAN and then to
FINAL BEAN
} else{
//DIRECTLY ROUTE TO FINAL BEAN
}
in.close();
}
I am passing an object to this bean as far as I know. How can I make it
relate to a message on which I can do setHeader ? Later this bean will just
return a message and I will have something like:
<camelContext id="camel"
xmlns="http://activemq.apache.org/camel/schema/spring">
<route>
<from uri="jms:topic:LoggingTopic"/>
<to uri="bean:msgParser"/>
<to uri="bean:contentRouter"/>
</route>
<route>
<from uri="bean:contentRouter"/>
<choice>
<when>
<xpath>$action = 'filterA'</xpath>
<to uri="bean:filter"/>
</when>
<otherwise>
<to uri="bean:final/>
</otherwise>
</choice>
</route>
</camelContext>
--
View this message in context: http://www.nabble.com/Content-Based-Router-tp20087651s22882p20087651.html
Sent from the Camel - Users mailing list archive at Nabble.com.