Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why not use Session Beans instead of Message Driven Beans?

I'm wondering, why not use Session Beans instead of Message Driven Beans ?

If you can call remote methods from EJBs, so why bother sending/receiving messages with Message Driven Beans (which is more difficult to develop than session beans) ?

In which scenarios Message Driven Beans become useful ?

like image 269
mohamida Avatar asked Oct 01 '10 08:10

mohamida


3 Answers

I'm wondering, why not use Session Beans instead of Message Driven Beans ?

Hmm, they don't serve the same purpose, message-driven beans allow Java EE applications to process messages asynchronously.

If you can call remote methods from EJBs, so why bother sending/receiving messages with Message Driven Beans (which is more difficult to develop than session beans) ?

Because MDBs give you asynchronism and loose coupling, which is something you might want/need in some situations:

  • for long running jobs
  • when resources are not always available
  • when you want to parallelize processing

By the way, I've personally always found MDBs to be the easiest Enterprise Beans to develop.

In which scenarios Message Driven Beans become useful ?

See above.

See also

  • What Is a Message-Driven Bean?
like image 57
Pascal Thivent Avatar answered Sep 24 '22 07:09

Pascal Thivent


Message driven beans listen to JMS queues asynchronously unlike entity/session beans.

This does not block server resources as the processing happens only when the message has arrived on the queue.

Other than loads of Java forums and sites, Wikipedia has a good set of usecases where MDBs come in handy

http://en.wikipedia.org/wiki/Enterprise_JavaBean#Message_driven_beans

like image 39
JoseK Avatar answered Sep 21 '22 07:09

JoseK


Both Serves Different purpose.

1) if you want to use it for just remote methods usage then just use Session Bean

2) but if responce/result not maters but the later message is mater to you then go for the JMS as it is creating the queue to make it work and to set the message. but perfomance issue will be there.

if u need to have just method usage then just use Session bean as it is light weight bean. and it is giving good performance.

like image 35
JavaSun Avatar answered Sep 23 '22 07:09

JavaSun