0

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.stop();
dmlc.setMessageSelector(String.format("retries < %d AND retryTime <= %d", z, System.currentTimeMillis()));
dmlc.start();

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.

Community
  • 1
  • 1
mman
  • 7
  • 2

1 Answers1

0

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.
MaDa
  • 10,511
  • 9
  • 46
  • 84
  • Thanks! I don't want to add Spring support to a small EJB application, that's why I need to do it in EJB. It is not about load balancing, rather more-or-less about the downtime and some othe business logic on the other other side of the communication. The possibility of the consumer to work the message successfully is nondeterministic. It could hapen next milliseconds, but sometime in 5 days. Here, it makes sense, AFAIK, to let the waiting time goes exponentioally growing. Besides, I could not figure it out, how to make Glassfish OpenMQ configured to accept such logic. any hints? – mman Dec 02 '11 at 13:30