- Apache ActiveMQ
- Apache Qpid
- FUSE Message Broker (enterprise ActiveMQ)
- Mantaray a P2P JMS implementation
- OpenJMS, from The OpenJMS Group
- JBoss Messaging from JBoss
- HornetQ from JBoss
- JORAM, from the OW2 Consortium
- Open Message Queue, from Sun Microsystems
- Sun Java System Message Queue, from Sun Microsystems, supported version of Open Message Queue
- Rabbit MQ
JMS provider | Implementation |
Oracle AQ | msg.setIntProperty(“JMS_OracleDelay”, delay); |
JBoss | msg.setLongProperty(“JMS_JBOSS_SCHEDULED_DELIVERY”, now + delay); |
ActiveMQ | msg.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, delay); |
OpenJMS | ((org.exolab.jms.message.MessageImpl)msg).setJMSXRcvTimestamp(now + delay); |
BEA Weblogic | queueConnection = queueConnectionFactory.createQueueConnection(); QueueSession queueSession = queueConnection.createQueueSession(true, 0); QueueSender queueSender = queueSession.createSender(queue); ObjectMessage jmsMsg = queueSession.createObjectMessage(message); //Casts queueSender to weblogic.jms.extensions.WLMessageProducer interface and set delivery time ((WLMessageProducer) queueSender).setTimeToDeliver(timeToDeliver); queueSender.send(jmsMsg); |
Do we have solution for JMS providers that do not have native support of delayed message delivery? Yes, we do. I would like to suggest the following solution.
Send message to special queue. Let’s call it DELAYED_QUEUE. Add to delayed message the special properties:
- JMS_DESTINATION that contains name of queue or topic where this message should be finally delivered.
- DELIVERY_TIME that contains time stamp in milliseconds (now + delay).
Scheduled task may be implemented as resource adapter (JCA):
BootstrapContext ctx;
ctx.getWorkManager().createTimer(). schedule(new DelayedMessageTimerTask(msg), new Date(now + delay))
This is not ideal solution. It is OK for relatively small number of messages and non persisted JMS destinations. Improvements of this solution are beyond the scope of this article.
Conclusions
Most popular JMS implementations support delayed delivery of messages. Even if this feature is not supported we can always implement it using additional queue and scheduled task.This article is published at DZone.
No comments:
Post a Comment