aspose file tools*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Ejb and JMS Interaction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Ejb and JMS Interaction" Watch "Ejb and JMS Interaction" New topic
Author

Ejb and JMS Interaction

Alessandro Aloisi
Greenhorn

Joined: Sep 07, 2010
Posts: 15
Hi Guys,
is about a day I am thinking that:

I have an ejb that have to interacts with a request/reply queue. Solution is quite simple: dependency injection and go.... but.... but....

IMHO ejb implements business logic, gathering information from external system through a queue could be done but is really business logic? Maybe yes, today the only business is interact with an external system, tomorrow will be other...

A proxy could abstract queue interaction and leave ejb concerned on its purpose, business!
so collaboration will be:
ejb->proxy->queue
but with a proxy I loose benefits of dependency injection and I have to implement a service locator and so on.....

mumble mumble....

What do you think?

Thanks in advance!


SCJP5, OCMJEA 5
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Session EJB are for implementing business logic.

Message-Driven EJB are for messaging. Business logic should not be in these types of EJB.
Alessandro Aloisi
Greenhorn

Joined: Sep 07, 2010
Posts: 15
Thanks for your response Jimmy.

I miss details!

My ejb is a stateless session bean and receives request from client and have to return availability. This availability is on an external system who my ejb calls through a jms request/reply.

So, the only thing of my ejb is to call external system by a queue, this is its business logic ( today! )

Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
What is making the call on the Session EJB and how come it doesn't post the message directly to the queue?
Alessandro Aloisi
Greenhorn

Joined: Sep 07, 2010
Posts: 15
Presentation asks level to my SLSB, I would like to leave this separation

Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Any reason why you are not using a Message-Driven EJB?
Alessandro Aloisi
Greenhorn

Joined: Sep 07, 2010
Posts: 15
Maybe I'm missing something but are not consumer? Listening on a queue.

My SLSB is a producer, send a message on queue e wait for a response ( this with a sync approach ) because requirements are a sync request from presentation tier and a jms integration with external system ( I have only this integration mechanism).
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Message-Driven EJB implementations receive messages and they can send messages just like your Session EJB.
Alessandro Aloisi
Greenhorn

Joined: Sep 07, 2010
Posts: 15
Yes but mbd fire on a message in the queue that this is listening viceversa, my requirement is to ask the external system when a client fire my business method.

Am I wronging something?

I really appreciate your help

Thanks
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Yes but mbd fire on a message...


What happens when a MDB "fires" on a message?
Alessandro Aloisi
Greenhorn

Joined: Sep 07, 2010
Posts: 15
Consumes the message...
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
What do you mean by "consume" a message? Please explain what "consume" means.
Alessandro Aloisi
Greenhorn

Joined: Sep 07, 2010
Posts: 15
according with java ee 5 jms api http://download.oracle.com/javaee/5/tutorial/doc/bnceh.html

A message consumer is an object that is created by a session and used for receiving messages sent to a destination

and for consume I mean that MDB receives the message sent on its queue ( "fires" the onMessage method )
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Ok. What I am asking is what happens when a MDB receives a message? What happens? What does the code in a MDB's onMessage() method actually do?
Alessandro Aloisi
Greenhorn

Joined: Sep 07, 2010
Posts: 15
Do you mean in general or in my solution?
In general, What happens? MDB elaborates it, what else?
For my problem, the message should contain availability of a product requested by ejb client...
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
You are not using a Message-Driven EJB, so I'm certainly not asking about your solution.

Let's put the MDB behaviour to the side a minute. We'll return later.

In your solution, when the client object calls the business method of your Session EJB, what happens? What does the code in your Session EJB method actually do?
Alessandro Aloisi
Greenhorn

Joined: Sep 07, 2010
Posts: 15
SLSB's method send a msg on a queue with a JMSReplyTo property setted, then it waits on the other queue for a response, like the jms requst/reply integration pattern http://www.eaipatterns.com/RequestReplyJmsExample.html

So, my doubt was: is correct to inject jms connection factory, queues, in my slsb or I have to use a proxy to abstract JMS interaction and leave the ejb free to think only its purpose, ask levels?
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
SLSB's method send a msg on a queue...


What would happen if you put your code that is in your Session EJB in a Message-Driven EJB's onMessage() method?

In regards to your doubt, in software design there are shades of good and shades of bad, and there is "working" and "not working." There is no "correct" and "incorrect" like a multiple choice question on a test.

Your decision to even use a Session EJB is questionable as you have not shown why a simple POJO business object is not sufficient. The client object in your Presentation can certainly communicate with a POJO business object. Here you still have separation.

Anyway, ideally you would not want to create a dependency between your application and the EJB API, so it is best to code the message handling in a plain Java class and then use one of these objects in your Session EJB. You never want to code actual business logic code statements in the EJB's bean class. The EJB is best used as a proxy itself.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ejb and JMS Interaction