views:

224

answers:

2

Hi everybody,

In most projects I have participated, the choice of an asynchronous solution has been a source of much discussion ...

Each time a single entity bean was enough to manage a queue: we just store a message (ticket) in a table and a processing cron unstacks the queue. This simple solution has the advantage of being very simple, it's based on the transactional context of the database and we can manage the state of the received message during its execution.

I therefore ask the following questions:

1) What interest we have to use JMS? What are the benefits of JMS ?

2) In which situation prefering JMS versus entity bean ?

Thank you for your responses and feedback!

+8  A: 

1) What interest we have to use JMS? What are the benefits of JMS ? 2) In which situation prefering JMS versus entity bean ?

You approach works well as long as there is only one consumer. Otherwise it will require a locking scheme so that the same message is not delivered twice, etc. This is what JMS offers out of the box: transacted production and consumption with the JMS broker managing all the delivery issues with multiple consumers/producers.

Other advantages of JMS are quality of service and management, e.g. redelivery attempt, dead message queue, load management, scalability, clustering, monitoring, etc.

JMS also support publish-subsribe or point-to-point.

It's a bit like comparing a JDBC statement to insert one row in database vs. a full-fledge ORM. Both work to insert a row in the db, but the ORM will provide a lot more, plus you don't re-invent the wheel to deal with low-level issues... (the analogy is not that great but well)

I suggest you look at the FAQ.

ewernli
Thanks for your reponse. I agree with you about having to reinvent the wheel with an entity bean and having to manage locking pattern in a multithread environnement. Ok, let's read the FAQ !
ajeanson
Note that I am not saying that JMS is *the* solution neither. Using JMS can complexity some aspect of the solution (e.g. dealing with distributed transactions, configuring the queues, managing messaging errors, etc.). If you have *one* consumer per queue and the *non-functional* issues are not a concern, then one table and a thread may well do the job. I've seen both approach and both worked.
ewernli
+2  A: 

So you decided to hammer together a database based message queue on your own instead of using an existing messaging system. Sure it will work, but I would ask why you even bothered with an entity bean, you have no state to maintain, or updates to make to the table, so you could just make db calls directly from a servlet (if web based) or a stateless session bean. All of which are still poor substitutes for an actual messaging system.

I realize that I didn't actually answer the question, but I thought I would point out that the existing solution seemed to be a case of, I have a hammer and now every problem looks like a nail.

Robin