This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ejb and JMS Interaction

 
Alessandro Aloisi
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Presentation asks level to my SLSB, I would like to leave this separation

 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any reason why you are not using a Message-Driven EJB?
 
Alessandro Aloisi
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Message-Driven EJB implementations receive messages and they can send messages just like your Session EJB.
 
Alessandro Aloisi
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes but mbd fire on a message...


What happens when a MDB "fires" on a message?
 
Alessandro Aloisi
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consumes the message...
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "consume" a message? Please explain what "consume" means.
 
Alessandro Aloisi
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic