You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by dunnlow <du...@yahoo.com> on 2011/07/11 14:25:25 UTC
How to use JMS TextMessage Properties?
This seems like it should be easy, but I cannot figure out how to obtain the
properties from a JMS TextMessage. I can obtain the body of the message
with ConvertBodyTo() but I also need the properties.
I'm using an ActiveMQ (v5.5) TestMessage and setting the properties in a
different java app like,
TextMessage message = session.createTextMessage();
message.setStringProperty("status1", status1);
message.setStringProperty("status2", status2);
message.setText(userMessage);
.
.
To read the Text message off the queue (with Camel 2.7.2) I have a route
like:
from("activemq:queue:myholdingqueue?testConnectionOnStartup=true").converBodyTo(String.class).to("stream:out");
This gives me the text of the message ("userMessage" above) but how do I get
the properties?
FYI, my end goal is to read those properties, verify the value (in a bean -
posibly changing the names of the properties) then storing the values into a
database.
Thanks for any insight.
J
--
View this message in context: http://camel.465427.n5.nabble.com/How-to-use-JMS-TextMessage-Properties-tp4574811p4574811.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: How to use JMS TextMessage Properties?
Posted by dunnlow <du...@yahoo.com>.
Claus,
Doh, I just reread your reply, and set the method declaration in my bean to
be:
public String toSql(org.apache.camel.Message obj) {
}
which, (surprise surprise) gives me just what i need. Thanks again!
--
View this message in context: http://camel.465427.n5.nabble.com/How-to-use-JMS-TextMessage-Properties-tp4574811p4574992.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: How to use JMS TextMessage Properties?
Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Jul 11, 2011 at 3:05 PM, dunnlow <du...@yahoo.com> wrote:
> Claus,
> Thanks for the reply (your book has been a HUGE help btw).
>
> Sorry, I am still missing something. I understand your comment about the
> stream component, which clears up one question. However, I tried passing
> the message to a bean, as:
>
> ("activemq:queue:myholdingqueue?testConnectionOnStartup=true").converBodyTo(String.class).beanRef("myCamelBean").to("stream:out");
>
> my bean is defined via Spring XML:
> <bean id="myCamelBean" class="com.mycc.beans.MyCamelBean"/>
>
> and the actual class just has one method:
>
> public String toSql(Object obj){
> System.out.println("class is "+obj.getClass().getName());
> if (obj.getClass().getName().equals("java.lang.String")){
> String sre = (String) obj;
> String.out.println("string is ["+str+"]");
> }
> }
>
> What I end up seeing on system.out is
> "class is java.lang.String"
> "string is [Hello this is the text in my TextMessage]"
>
> My question:
>
> 1) If I leave the "ConvertBodyTo()" out of the route, the bean never seems
> to be called. Why is that?
>
You use Object as the type of the method. That is too broad in the sense.
> 2) I was expecting that my bean would get some sort of message object from
> which I could call a getProperty, but it only gets a string with the header
> (with the ConvertBodyTo). Is there something else I should be using to get
> the message to my Bean?
>
You can use one of the Camel APIs to get the Camel Message such as
public String toSql(Exchange exchange){
Then you can access the headers and body as follows
String body = exchange.getIn().getBody(String.class);
Map<String, Object> headers = exchange.getIn().getHeaders();
You may want to read chapter 3 and 4 to see how you can use beans /
processors etc with Camel.
> Thanks again.
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-to-use-JMS-TextMessage-Properties-tp4574811p4574918.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
Re: How to use JMS TextMessage Properties?
Posted by dunnlow <du...@yahoo.com>.
Claus,
Thanks for the reply (your book has been a HUGE help btw).
Sorry, I am still missing something. I understand your comment about the
stream component, which clears up one question. However, I tried passing
the message to a bean, as:
("activemq:queue:myholdingqueue?testConnectionOnStartup=true").converBodyTo(String.class).beanRef("myCamelBean").to("stream:out");
my bean is defined via Spring XML:
<bean id="myCamelBean" class="com.mycc.beans.MyCamelBean"/>
and the actual class just has one method:
public String toSql(Object obj){
System.out.println("class is "+obj.getClass().getName());
if (obj.getClass().getName().equals("java.lang.String")){
String sre = (String) obj;
String.out.println("string is ["+str+"]");
}
}
What I end up seeing on system.out is
"class is java.lang.String"
"string is [Hello this is the text in my TextMessage]"
My question:
1) If I leave the "ConvertBodyTo()" out of the route, the bean never seems
to be called. Why is that?
2) I was expecting that my bean would get some sort of message object from
which I could call a getProperty, but it only gets a string with the header
(with the ConvertBodyTo). Is there something else I should be using to get
the message to my Bean?
Thanks again.
--
View this message in context: http://camel.465427.n5.nabble.com/How-to-use-JMS-TextMessage-Properties-tp4574811p4574918.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: How to use JMS TextMessage Properties?
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
JMS properties get mapped to Camel headers. There is some details here
http://camel.apache.org/jms
The stream component will only output the message body.
If you use the log component then you can instruct it to output all
kind of sorts
http://camel.apache.org/log
.to("log:foo?showHeaders=true")
You can access the message body and headers from the Camel Message
instance (org.apache.camel.Message).
If you use Java code you can use a java bean, or a Camel Processor to
access the message
http://camel.apache.org/bean-binding.html
http://camel.apache.org/processor
On Mon, Jul 11, 2011 at 2:25 PM, dunnlow <du...@yahoo.com> wrote:
> This seems like it should be easy, but I cannot figure out how to obtain the
> properties from a JMS TextMessage. I can obtain the body of the message
> with ConvertBodyTo() but I also need the properties.
>
> I'm using an ActiveMQ (v5.5) TestMessage and setting the properties in a
> different java app like,
>
> TextMessage message = session.createTextMessage();
> message.setStringProperty("status1", status1);
> message.setStringProperty("status2", status2);
> message.setText(userMessage);
> .
> .
>
> To read the Text message off the queue (with Camel 2.7.2) I have a route
> like:
>
> from("activemq:queue:myholdingqueue?testConnectionOnStartup=true").converBodyTo(String.class).to("stream:out");
>
> This gives me the text of the message ("userMessage" above) but how do I get
> the properties?
>
> FYI, my end goal is to read those properties, verify the value (in a bean -
> posibly changing the names of the properties) then storing the values into a
> database.
>
> Thanks for any insight.
>
> J
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-to-use-JMS-TextMessage-Properties-tp4574811p4574811.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
Re: How to use JMS TextMessage Properties?
Posted by ayimer <ah...@gmail.com>.
Hello dunnlow,
Can you post the sample code? I have the same requirements like yours...
--
View this message in context: http://camel.465427.n5.nabble.com/How-to-use-JMS-TextMessage-Properties-tp4574811p5745310.html
Sent from the Camel - Users mailing list archive at Nabble.com.