You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by marcuse <kr...@gmail.com> on 2009/09/15 14:49:32 UTC

Bootstrapping camel from MDB

Hi

I have a project which uses MDBs, and I want to try using camel for routing
incoming messages to various message handlers, googling showed me
http://camel.apache.org/maven/camel-jms/apidocs/org/apache/camel/component/jms/CamelMessageListener.html
but this seems removed from camel 2.0.

Also looked at the source for CamelMessageListener to reproduce the
functionality, but I did not get by the fact that JmsExchange was removed

So, my question is, what is the best practise for using camel from an MDB?

/Marcus
-- 
View this message in context: http://www.nabble.com/Bootstrapping-camel-from-MDB-tp25453382p25453382.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Bootstrapping camel from MDB

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Sep 16, 2009 at 8:45 AM, marcuse <kr...@gmail.com> wrote:
>
> The thing is that i want to be able to route based on headers in the jms
> message
>
> any source code pointers so that i can try to replicate the real jms
> behaviour in the onMessage method?
>

All in camel-jms :)

I think you can reuse the JmsBinding that does the heavy work.
Something like this:

Exchange exchange = new DefaultExchange(camelContext);
JmsBinding binding = new JmsBinding();

Object payload = binding.extractBodyFromJms(exchange, theJmsMessage);
Map headers = binding.extractHeadersFromJms(theJmsMessage, exchange);

exchange.getIn().setBody(payload);
exchange.getIn().setHeaders(headers);

// and then send it
template.send("where to buddy", exchange);


You need camel-jms on the classpath.




>
>
> Claus Ibsen-2 wrote:
>>
>> On Wed, Sep 16, 2009 at 8:07 AM, marcuse <kr...@gmail.com> wrote:
>>>
>>> Yes it is a real EJB MDB
>>>
>>> So I just set up my camel context & ProducerTemplate in the MDB
>>> constructor
>>> and then in the onMessage method i do
>>> producerTemplate.sendBody("whatever",theJmsMessage); ?
>>
>> Yeah pretty much. As you are not using the camel-jms to receive the
>> JMS message it have not done its bidning from JMS world to Java world
>> which means that extraating JMS body, and JMS properties cannot be
>> done automatic by Camel. Which may require you to do that manually if
>> you need them.
>>
>> // for example to extract the jms as a text message
>> String text = ((TextMessage) message).getText();
>> producerTemplate.sendBody("whatever", text);
>>
>> However Camel also have its type converter mechanism which may support
>> this out of the box. I gotta check the source to be sure. As you are
>> the first with that must use MDB.
>>
>>
>>>
>>> /Marcus
>>>
>>>
>>>
>>> Claus Ibsen-2 wrote:
>>>>
>>>> On Tue, Sep 15, 2009 at 2:49 PM, marcuse <kr...@gmail.com> wrote:
>>>>>
>>>>> Hi
>>>>>
>>>>> I have a project which uses MDBs, and I want to try using camel for
>>>>> routing
>>>>> incoming messages to various message handlers, googling showed me
>>>>> http://camel.apache.org/maven/camel-jms/apidocs/org/apache/camel/component/jms/CamelMessageListener.html
>>>>> but this seems removed from camel 2.0.
>>>>>
>>>>> Also looked at the source for CamelMessageListener to reproduce the
>>>>> functionality, but I did not get by the fact that JmsExchange was
>>>>> removed
>>>>>
>>>>> So, my question is, what is the best practise for using camel from an
>>>>> MDB?
>>>>>
>>>>
>>>> You are using real EJB MDB, if I understand you correctly?
>>>>
>>>> And then you want in the onMessage(Message msg) method to route the
>>>> message with Camel?
>>>>
>>>> You can take a look at this example:
>>>> http://camel.apache.org/walk-through-an-example.html
>>>>
>>>> Where you can setup Camel manually in the MDB and then use it to route
>>>> the message.
>>>>
>>>>
>>>> Camel itself can of course also listen to JMS queues, in case you not
>>>> need to use MDB.
>>>>
>>>>
>>>>> /Marcus
>>>>> --
>>>>> View this message in context:
>>>>> http://www.nabble.com/Bootstrapping-camel-from-MDB-tp25453382p25453382.html
>>>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Claus Ibsen
>>>> Apache Camel Committer
>>>>
>>>> Open Source Integration: http://fusesource.com
>>>> Blog: http://davsclaus.blogspot.com/
>>>> Twitter: http://twitter.com/davsclaus
>>>>
>>>>
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Bootstrapping-camel-from-MDB-tp25453382p25466487.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>>
>> --
>> Claus Ibsen
>> Apache Camel Committer
>>
>> Open Source Integration: http://fusesource.com
>> Blog: http://davsclaus.blogspot.com/
>> Twitter: http://twitter.com/davsclaus
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Bootstrapping-camel-from-MDB-tp25453382p25466871.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: Bootstrapping camel from MDB

Posted by marcuse <kr...@gmail.com>.
The thing is that i want to be able to route based on headers in the jms
message

any source code pointers so that i can try to replicate the real jms
behaviour in the onMessage method?



Claus Ibsen-2 wrote:
> 
> On Wed, Sep 16, 2009 at 8:07 AM, marcuse <kr...@gmail.com> wrote:
>>
>> Yes it is a real EJB MDB
>>
>> So I just set up my camel context & ProducerTemplate in the MDB
>> constructor
>> and then in the onMessage method i do
>> producerTemplate.sendBody("whatever",theJmsMessage); ?
> 
> Yeah pretty much. As you are not using the camel-jms to receive the
> JMS message it have not done its bidning from JMS world to Java world
> which means that extraating JMS body, and JMS properties cannot be
> done automatic by Camel. Which may require you to do that manually if
> you need them.
> 
> // for example to extract the jms as a text message
> String text = ((TextMessage) message).getText();
> producerTemplate.sendBody("whatever", text);
> 
> However Camel also have its type converter mechanism which may support
> this out of the box. I gotta check the source to be sure. As you are
> the first with that must use MDB.
> 
> 
>>
>> /Marcus
>>
>>
>>
>> Claus Ibsen-2 wrote:
>>>
>>> On Tue, Sep 15, 2009 at 2:49 PM, marcuse <kr...@gmail.com> wrote:
>>>>
>>>> Hi
>>>>
>>>> I have a project which uses MDBs, and I want to try using camel for
>>>> routing
>>>> incoming messages to various message handlers, googling showed me
>>>> http://camel.apache.org/maven/camel-jms/apidocs/org/apache/camel/component/jms/CamelMessageListener.html
>>>> but this seems removed from camel 2.0.
>>>>
>>>> Also looked at the source for CamelMessageListener to reproduce the
>>>> functionality, but I did not get by the fact that JmsExchange was
>>>> removed
>>>>
>>>> So, my question is, what is the best practise for using camel from an
>>>> MDB?
>>>>
>>>
>>> You are using real EJB MDB, if I understand you correctly?
>>>
>>> And then you want in the onMessage(Message msg) method to route the
>>> message with Camel?
>>>
>>> You can take a look at this example:
>>> http://camel.apache.org/walk-through-an-example.html
>>>
>>> Where you can setup Camel manually in the MDB and then use it to route
>>> the message.
>>>
>>>
>>> Camel itself can of course also listen to JMS queues, in case you not
>>> need to use MDB.
>>>
>>>
>>>> /Marcus
>>>> --
>>>> View this message in context:
>>>> http://www.nabble.com/Bootstrapping-camel-from-MDB-tp25453382p25453382.html
>>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> Claus Ibsen
>>> Apache Camel Committer
>>>
>>> Open Source Integration: http://fusesource.com
>>> Blog: http://davsclaus.blogspot.com/
>>> Twitter: http://twitter.com/davsclaus
>>>
>>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Bootstrapping-camel-from-MDB-tp25453382p25466487.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
> 
> 
> 
> -- 
> Claus Ibsen
> Apache Camel Committer
> 
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
> 
> 

-- 
View this message in context: http://www.nabble.com/Bootstrapping-camel-from-MDB-tp25453382p25466871.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Bootstrapping camel from MDB

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Sep 16, 2009 at 8:07 AM, marcuse <kr...@gmail.com> wrote:
>
> Yes it is a real EJB MDB
>
> So I just set up my camel context & ProducerTemplate in the MDB constructor
> and then in the onMessage method i do
> producerTemplate.sendBody("whatever",theJmsMessage); ?

Yeah pretty much. As you are not using the camel-jms to receive the
JMS message it have not done its bidning from JMS world to Java world
which means that extraating JMS body, and JMS properties cannot be
done automatic by Camel. Which may require you to do that manually if
you need them.

// for example to extract the jms as a text message
String text = ((TextMessage) message).getText();
producerTemplate.sendBody("whatever", text);

However Camel also have its type converter mechanism which may support
this out of the box. I gotta check the source to be sure. As you are
the first with that must use MDB.


>
> /Marcus
>
>
>
> Claus Ibsen-2 wrote:
>>
>> On Tue, Sep 15, 2009 at 2:49 PM, marcuse <kr...@gmail.com> wrote:
>>>
>>> Hi
>>>
>>> I have a project which uses MDBs, and I want to try using camel for
>>> routing
>>> incoming messages to various message handlers, googling showed me
>>> http://camel.apache.org/maven/camel-jms/apidocs/org/apache/camel/component/jms/CamelMessageListener.html
>>> but this seems removed from camel 2.0.
>>>
>>> Also looked at the source for CamelMessageListener to reproduce the
>>> functionality, but I did not get by the fact that JmsExchange was removed
>>>
>>> So, my question is, what is the best practise for using camel from an
>>> MDB?
>>>
>>
>> You are using real EJB MDB, if I understand you correctly?
>>
>> And then you want in the onMessage(Message msg) method to route the
>> message with Camel?
>>
>> You can take a look at this example:
>> http://camel.apache.org/walk-through-an-example.html
>>
>> Where you can setup Camel manually in the MDB and then use it to route
>> the message.
>>
>>
>> Camel itself can of course also listen to JMS queues, in case you not
>> need to use MDB.
>>
>>
>>> /Marcus
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Bootstrapping-camel-from-MDB-tp25453382p25453382.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>>
>> --
>> Claus Ibsen
>> Apache Camel Committer
>>
>> Open Source Integration: http://fusesource.com
>> Blog: http://davsclaus.blogspot.com/
>> Twitter: http://twitter.com/davsclaus
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Bootstrapping-camel-from-MDB-tp25453382p25466487.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: Bootstrapping camel from MDB

Posted by marcuse <kr...@gmail.com>.
Yes it is a real EJB MDB

So I just set up my camel context & ProducerTemplate in the MDB constructor
and then in the onMessage method i do
producerTemplate.sendBody("whatever",theJmsMessage); ?

/Marcus



Claus Ibsen-2 wrote:
> 
> On Tue, Sep 15, 2009 at 2:49 PM, marcuse <kr...@gmail.com> wrote:
>>
>> Hi
>>
>> I have a project which uses MDBs, and I want to try using camel for
>> routing
>> incoming messages to various message handlers, googling showed me
>> http://camel.apache.org/maven/camel-jms/apidocs/org/apache/camel/component/jms/CamelMessageListener.html
>> but this seems removed from camel 2.0.
>>
>> Also looked at the source for CamelMessageListener to reproduce the
>> functionality, but I did not get by the fact that JmsExchange was removed
>>
>> So, my question is, what is the best practise for using camel from an
>> MDB?
>>
> 
> You are using real EJB MDB, if I understand you correctly?
> 
> And then you want in the onMessage(Message msg) method to route the
> message with Camel?
> 
> You can take a look at this example:
> http://camel.apache.org/walk-through-an-example.html
> 
> Where you can setup Camel manually in the MDB and then use it to route
> the message.
> 
> 
> Camel itself can of course also listen to JMS queues, in case you not
> need to use MDB.
> 
> 
>> /Marcus
>> --
>> View this message in context:
>> http://www.nabble.com/Bootstrapping-camel-from-MDB-tp25453382p25453382.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
> 
> 
> 
> -- 
> Claus Ibsen
> Apache Camel Committer
> 
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
> 
> 

-- 
View this message in context: http://www.nabble.com/Bootstrapping-camel-from-MDB-tp25453382p25466487.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Bootstrapping camel from MDB

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Sep 15, 2009 at 2:49 PM, marcuse <kr...@gmail.com> wrote:
>
> Hi
>
> I have a project which uses MDBs, and I want to try using camel for routing
> incoming messages to various message handlers, googling showed me
> http://camel.apache.org/maven/camel-jms/apidocs/org/apache/camel/component/jms/CamelMessageListener.html
> but this seems removed from camel 2.0.
>
> Also looked at the source for CamelMessageListener to reproduce the
> functionality, but I did not get by the fact that JmsExchange was removed
>
> So, my question is, what is the best practise for using camel from an MDB?
>

You are using real EJB MDB, if I understand you correctly?

And then you want in the onMessage(Message msg) method to route the
message with Camel?

You can take a look at this example:
http://camel.apache.org/walk-through-an-example.html

Where you can setup Camel manually in the MDB and then use it to route
the message.


Camel itself can of course also listen to JMS queues, in case you not
need to use MDB.


> /Marcus
> --
> View this message in context: http://www.nabble.com/Bootstrapping-camel-from-MDB-tp25453382p25453382.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus