You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Jar Lyons <ja...@tideworks.com> on 2008/02/07 19:01:08 UTC

How do I get a Content Based Router configured in XML with ActiveMQ?

I have been trying for days now to get a message based router working in
ActiveMQ 5.1, and the only success I have had is with xpath.

Unfortunately, xpath will only work when the message body is xml ... which
often is not the case for me.

Here is an example of what does work (assuming the message body is xml):

    <route>
      <from uri="activemq:queue.dev.Tideworks.HelloWorld"/>
      <filter>
        <xpath>$JMSType = 'Tideworks.GateVision.OCR.Lane'</xpath>
        <to uri="activemq:queue.dev.Tideworks.HelloWorld"/>
      </filter>
    </route>

So ... once I realized this only works with fully xml message bodies, I
tried all of the following, with no luck  ...

  <route>
    <from uri="activemq:queue.dev.Tideworks.HelloWorld"/>
    <filter>
        <simple>property.JMSType = 'Tideworks.GateVision.OCR.Lane'</simple>
        <to uri="activemq:queue.dev.Tideworks.HelloWorld.it_works"/>
    </filter>
  </route>

  <route>
    <from uri="activemq:queue.dev.Tideworks.HelloWorld"/>
    <filter>
        <el>in.headers.jmstype startswith 'Tideworks'</el>
        <to uri="activemq:queue.dev.Tideworks.HelloWorld.it_works"/>
    </filter>
  </route>

All of the above configurations will load and run without throwing
exceptions, but only the xpath example will do what I want.  And again, I
need to be able to operate with non-xml messages.

In the ideal world, I would use a filter that allows me to use the same
style JMS selector expressions that a developer would be accustomed to using
when configuring a MessageDrivenBean.

I must be missing something very obvious here ....

Configuration:

ActiveMQ 5.1
Camel 1.2 (and also tried 1.3)
Redhat and Windows XP

Camel libraries included in the activemq/lib directory .....

../lib/camel-core-1.2.0.jar    ../lib/camel-jms-1.2.0.jar   
../lib/camel-juel-1.2.0.jar   ../lib/camel-spring-1.2.0.jar
../lib/camel-groovy-1.2.0.jar  ../lib/camel-josql-1.2.0.jar 
../lib/camel-saxon-1.2.0.jar



-- 
View this message in context: http://www.nabble.com/How-do-I-get-a-Content-Based-Router-configured-in-XML-with-ActiveMQ--tp15339501s22882p15339501.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: How do I get a Content Based Router configured in XML with ActiveMQ?

Posted by James Strachan <ja...@gmail.com>.
On 15/03/2008, Jar Lyons <ja...@tideworks.com> wrote:
>
>  James,
>
>  I got the latest from the trunk and got juel working just fine.  Thank
>  You!!!
>
>  My last hurdle is how to route based on JMS message properties ....   It
>  doesn't look like the properties are available in juel .... so I tried going
>  after a property using the 'simple' syntax, but no joy ...
>
>       <filter>
>
>  <simple>${in.header.JMSType.startsWith('RTLS.draymanLocate')}</simple>
>         <to uri=.......>
>       </filter>
>
>  Are the properties easily available via any of the standard expression
>  languages?  And if so, what exactly is the syntax?

Yes - you should be able to look up headers by name. I've just added a
few more test cases to JuelLanguageTest to show some real examples.

So you should be able to do

${in.headers.JMSType == 'foo'}

or use the string lookup for non-identifier based property names

${in.headers.['Content-Type'] == 'application/xml'}

etc

If you hit some issues with an expression language - such as JUEL -
you could hack the JuelLanguageTest to try things out to check your
expression is valid etc.

-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com

Re: How do I get a Content Based Router configured in XML with ActiveMQ?

Posted by Jar Lyons <ja...@tideworks.com>.
James,

I got the latest from the trunk and got juel working just fine.  Thank
You!!!

My last hurdle is how to route based on JMS message properties ....   It
doesn't look like the properties are available in juel .... so I tried going
after a property using the 'simple' syntax, but no joy ...

      <filter>
       
<simple>${in.header.JMSType.startsWith('RTLS.draymanLocate')}</simple>
        <to uri=.......>
      </filter>

Are the properties easily available via any of the standard expression
languages?  And if so, what exactly is the syntax?

I'd be happy to contribute some of my final settings to the site as examples
....

Jar




James.Strachan wrote:
> 
> On 07/02/2008, Jar Lyons <ja...@tideworks.com> wrote:
>>
>> I have been trying for days now to get a message based router working in
>> ActiveMQ 5.1, and the only success I have had is with xpath.
>>
>> Unfortunately, xpath will only work when the message body is xml ...
>> which
>> often is not the case for me.
>>
>> Here is an example of what does work (assuming the message body is xml):
>>
>>     <route>
>>       <from uri="activemq:queue.dev.Tideworks.HelloWorld"/>
>>       <filter>
>>         <xpath>$JMSType = 'Tideworks.GateVision.OCR.Lane'</xpath>
>>         <to uri="activemq:queue.dev.Tideworks.HelloWorld"/>
>>       </filter>
>>     </route>
>>
>> So ... once I realized this only works with fully xml message bodies, I
>> tried all of the following, with no luck  ...
>>
>>   <route>
>>     <from uri="activemq:queue.dev.Tideworks.HelloWorld"/>
>>     <filter>
>>         <simple>property.JMSType =
>> 'Tideworks.GateVision.OCR.Lane'</simple>
>>         <to uri="activemq:queue.dev.Tideworks.HelloWorld.it_works"/>
>>     </filter>
>>   </route>
>>
>>   <route>
>>     <from uri="activemq:queue.dev.Tideworks.HelloWorld"/>
>>     <filter>
>>         <el>in.headers.jmstype startswith 'Tideworks'</el>
>>         <to uri="activemq:queue.dev.Tideworks.HelloWorld.it_works"/>
>>     </filter>
>>   </route>
>>
>> All of the above configurations will load and run without throwing
>> exceptions, but only the xpath example will do what I want.  And again, I
>> need to be able to operate with non-xml messages.
>>
>> In the ideal world, I would use a filter that allows me to use the same
>> style JMS selector expressions that a developer would be accustomed to
>> using
>> when configuring a MessageDrivenBean.
>>
>> I must be missing something very obvious here ....
> 
> I guess one option could be to add JMS SQL selector syntax into the
> filter as a language, which wouldn't be too hard.
> 
> For non-XML payloads then EL is probably the best choice (or OGNL if
> you know its syntax).
> 
> Its mostly a question of getting the EL expression correct for what
> you need. Maybe a little JUnit test case can help you experiment with
> EL expression (e.g. see the JuelLanguageTest in the camel-juel module
> for a place you can experiment).
> 
> FWIW I thought JUEL had method invocation enabled by default - it
> turns out it doesn't :). I've just raised this issue...
> https://issues.apache.org/activemq/browse/CAMEL-347
> 
> its now been fixed in trunk; so you can use expressions like:
> 
> ${in.headers.foo.startsWith('a')}
> 
> with JUEL and it works with method calls. Note with EL you use ${}
> around the dyamic bits - as JUEL can be used to create Strings too.
> 
> e.g. the following is valid JUEL
> 
> <el>hello ${in.header.name} how are you?</el>
> 
> -- 
> James
> -------
> http://macstrac.blogspot.com/
> 
> Open Source Integration
> http://open.iona.com
> 
> 

-- 
View this message in context: http://www.nabble.com/How-do-I-get-a-Content-Based-Router-configured-in-XML-with-ActiveMQ--tp15339501s22882p16063142.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: How do I get a Content Based Router configured in XML with ActiveMQ?

Posted by James Strachan <ja...@gmail.com>.
On 28/02/2008, Jar Lyons <ja...@tideworks.com> wrote:
>
>  Thank you James!!
>
>  I'll get the latest drop and try out Juel.
>
>  Also, I strongly recommend adding the JMS SQL style selector capability, as
>  it will make for a much easier sell for projects considering switching to
>  ActiveMQ ... who are already working with legacy enterprise messaging
>  brokers, like Tibco (which rely quite heavily on this mechanism).

I've raised a JIRA to track this issue...
https://issues.apache.org/activemq/browse/CAMEL-349

-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com

Re: How do I get a Content Based Router configured in XML with ActiveMQ?

Posted by Jar Lyons <ja...@tideworks.com>.
Thank you James!!

I'll get the latest drop and try out Juel.

Also, I strongly recommend adding the JMS SQL style selector capability, as
it will make for a much easier sell for projects considering switching to
ActiveMQ ... who are already working with legacy enterprise messaging
brokers, like Tibco (which rely quite heavily on this mechanism).



James.Strachan wrote:
> 
> On 07/02/2008, Jar Lyons <ja...@tideworks.com> wrote:
>>
>> I have been trying for days now to get a message based router working in
>> ActiveMQ 5.1, and the only success I have had is with xpath.
>>
>> Unfortunately, xpath will only work when the message body is xml ...
>> which
>> often is not the case for me.
>>
>> Here is an example of what does work (assuming the message body is xml):
>>
>>     <route>
>>       <from uri="activemq:queue.dev.Tideworks.HelloWorld"/>
>>       <filter>
>>         <xpath>$JMSType = 'Tideworks.GateVision.OCR.Lane'</xpath>
>>         <to uri="activemq:queue.dev.Tideworks.HelloWorld"/>
>>       </filter>
>>     </route>
>>
>> So ... once I realized this only works with fully xml message bodies, I
>> tried all of the following, with no luck  ...
>>
>>   <route>
>>     <from uri="activemq:queue.dev.Tideworks.HelloWorld"/>
>>     <filter>
>>         <simple>property.JMSType =
>> 'Tideworks.GateVision.OCR.Lane'</simple>
>>         <to uri="activemq:queue.dev.Tideworks.HelloWorld.it_works"/>
>>     </filter>
>>   </route>
>>
>>   <route>
>>     <from uri="activemq:queue.dev.Tideworks.HelloWorld"/>
>>     <filter>
>>         <el>in.headers.jmstype startswith 'Tideworks'</el>
>>         <to uri="activemq:queue.dev.Tideworks.HelloWorld.it_works"/>
>>     </filter>
>>   </route>
>>
>> All of the above configurations will load and run without throwing
>> exceptions, but only the xpath example will do what I want.  And again, I
>> need to be able to operate with non-xml messages.
>>
>> In the ideal world, I would use a filter that allows me to use the same
>> style JMS selector expressions that a developer would be accustomed to
>> using
>> when configuring a MessageDrivenBean.
>>
>> I must be missing something very obvious here ....
> 
> I guess one option could be to add JMS SQL selector syntax into the
> filter as a language, which wouldn't be too hard.
> 
> For non-XML payloads then EL is probably the best choice (or OGNL if
> you know its syntax).
> 
> Its mostly a question of getting the EL expression correct for what
> you need. Maybe a little JUnit test case can help you experiment with
> EL expression (e.g. see the JuelLanguageTest in the camel-juel module
> for a place you can experiment).
> 
> FWIW I thought JUEL had method invocation enabled by default - it
> turns out it doesn't :). I've just raised this issue...
> https://issues.apache.org/activemq/browse/CAMEL-347
> 
> its now been fixed in trunk; so you can use expressions like:
> 
> ${in.headers.foo.startsWith('a')}
> 
> with JUEL and it works with method calls. Note with EL you use ${}
> around the dyamic bits - as JUEL can be used to create Strings too.
> 
> e.g. the following is valid JUEL
> 
> <el>hello ${in.header.name} how are you?</el>
> 
> -- 
> James
> -------
> http://macstrac.blogspot.com/
> 
> Open Source Integration
> http://open.iona.com
> 
> 

-- 
View this message in context: http://www.nabble.com/How-do-I-get-a-Content-Based-Router-configured-in-XML-with-ActiveMQ--tp15339501s22882p15741806.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: How do I get a Content Based Router configured in XML with ActiveMQ?

Posted by James Strachan <ja...@gmail.com>.
On 07/02/2008, Jar Lyons <ja...@tideworks.com> wrote:
>
> I have been trying for days now to get a message based router working in
> ActiveMQ 5.1, and the only success I have had is with xpath.
>
> Unfortunately, xpath will only work when the message body is xml ... which
> often is not the case for me.
>
> Here is an example of what does work (assuming the message body is xml):
>
>     <route>
>       <from uri="activemq:queue.dev.Tideworks.HelloWorld"/>
>       <filter>
>         <xpath>$JMSType = 'Tideworks.GateVision.OCR.Lane'</xpath>
>         <to uri="activemq:queue.dev.Tideworks.HelloWorld"/>
>       </filter>
>     </route>
>
> So ... once I realized this only works with fully xml message bodies, I
> tried all of the following, with no luck  ...
>
>   <route>
>     <from uri="activemq:queue.dev.Tideworks.HelloWorld"/>
>     <filter>
>         <simple>property.JMSType = 'Tideworks.GateVision.OCR.Lane'</simple>
>         <to uri="activemq:queue.dev.Tideworks.HelloWorld.it_works"/>
>     </filter>
>   </route>
>
>   <route>
>     <from uri="activemq:queue.dev.Tideworks.HelloWorld"/>
>     <filter>
>         <el>in.headers.jmstype startswith 'Tideworks'</el>
>         <to uri="activemq:queue.dev.Tideworks.HelloWorld.it_works"/>
>     </filter>
>   </route>
>
> All of the above configurations will load and run without throwing
> exceptions, but only the xpath example will do what I want.  And again, I
> need to be able to operate with non-xml messages.
>
> In the ideal world, I would use a filter that allows me to use the same
> style JMS selector expressions that a developer would be accustomed to using
> when configuring a MessageDrivenBean.
>
> I must be missing something very obvious here ....

I guess one option could be to add JMS SQL selector syntax into the
filter as a language, which wouldn't be too hard.

For non-XML payloads then EL is probably the best choice (or OGNL if
you know its syntax).

Its mostly a question of getting the EL expression correct for what
you need. Maybe a little JUnit test case can help you experiment with
EL expression (e.g. see the JuelLanguageTest in the camel-juel module
for a place you can experiment).

FWIW I thought JUEL had method invocation enabled by default - it
turns out it doesn't :). I've just raised this issue...
https://issues.apache.org/activemq/browse/CAMEL-347

its now been fixed in trunk; so you can use expressions like:

${in.headers.foo.startsWith('a')}

with JUEL and it works with method calls. Note with EL you use ${}
around the dyamic bits - as JUEL can be used to create Strings too.

e.g. the following is valid JUEL

<el>hello ${in.header.name} how are you?</el>

-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com