Making EJB MessageDrivenBean work like DefaultMessageListenerContainer (JMS, OpenMQ)

I am using the Spring DefaultMessageListenerContainer to gain some dynamic benefits in setting the MessageSelector value since I am using the Glassfish OpenMQ which is not that advanced in that regards. Let's have a JMS message. The listener issues a specific failure that means: retry after x seconds. It tries again with failure: retry after x*y seconds, and so on the time grows exponentially. If you cannot handle it after z retries, consider it as a poison JMS message.

DefaultMessageListenerContainer dmlc;
dmlc.setMessageSelector(String.format("retries < %d AND retryTime <= %d", z, System.currentTimeMillis()));

I am not that satisfied with this solution, especially, when the Spring docs raise warning here:-). However, for the moment things meet our needs.

Now, I have a number of EJBs message consumers on different applications. Some of them need such dynamic changes of the messageSelector. Unfortunately, and to-my-best-knowledge, EJB MDBs do not support such dynamic "features". For example, see this.

Is that correct? is there a workaround for an EJB solution? I would appreciate any help.


To achieve dynamic changes to the message selector, you'd need to implement it straight in JMS, e.g.

ConnectionFactory cf;
Connection connection = cf.createConnection();
session = connection.createSession(transactional, acknowledgeMode);

MessageConsumer messageConsumer = session.createConsumer(destination, "message selector");

Additionally, you'd need to place this code some place it executes on its own, perhaps in an asynchronous task? But you'd be reinventing the wheel, as Spring DMLC does that better.

I don't know why you're doing this:

  • for load balancing? The message broker should take care of this.
  • for handling temporary downtimes? The queue should be configured to be able to store appropriate number of messages, or switch delivery to other node in cluster.

Need Your Help

Swift: Want to add Array to an existing Dictionary

ios swift dictionary

Have a JSON object with all conversations, and a JSON object with all messages from a specific conversation. Those JSON objects get parsed and put the values in a Dictionary and then in an Array. S...

Name of control for toggle boxes in sharepoint editor part

sharepoint controls web-parts

I'm trying to modify the EditorPart controller for my web part. Basically what I want is to have my custom controls inside a box like the standard properties that can toggle between visible and hid...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.