activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From manav <vyakaranam_2...@yahoo.com>
Subject Expired Message Listener
Date Thu, 22 Feb 2007 04:22:29 GMT

We recently migrated our application from ActiveMQ3.2.1 to ActiveMQ 4.1.0.

We were using a listener for Expired messages (after timetolive) when we
used ActiveMQ 3.2.1 using DeadLetterPolicy class.

When we switched to ActiveMQ 4.1, we noticed that the DeadLetterPolicy class
has been changed in 4.1 and thus started to look around on how to listen to
expired messages.

All we want to do after listening to the messages is to log a message in out
application logs and make an audit entry (application specific). 

In ActiveMQ 3.2.1, we used the below code that uses the
org.activemq.deadletter.Destination concept to receive the expired messages.
This code worked like a charm in 3.2.1. Now we would like to achieve the
same functionality with AMQ4.1. Could someone please help us out with
equivalent code for 4.1?

//Code used with ActiveMQ3.2.1 for listening to expired messages..
import org.activemq.service.DeadLetterPolicy;

String dlqName = "org.activemq.deadletter.InquiryDestination";
Queue dlqDestination = session.createQueue(dlqName);

consumer = session.createReceiver(dlqDestination);
consumer.setMessageListener(new InquiryMessageListner());
			
DeadLetterPolicy dlq = new DeadLetterPolicy();
connection = connectionFactory.createQueueConnection();
session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue destination = session.createQueue("InquiryDestination");
String dlqName =
dlq.getDeadLetterNameFromDestination((ActiveMQDestination)destination);
Queue dlqDestination = session.createQueue(dlqName);



class InquiryMessageListner implements MessageListener {  
	private static AuditHelper auditImpl = new AuditHelper();
   	public void onMessage(Message message) {
		TextMessage txtMsg = (TextMessage) message;
		try {
			MIBLogger.messageDead(txtMsg.getJMSCorrelationID(),
MIBConstants.DLQREASON_REQQ);
			auditImpl.logSuccessEvent(AuditHelper.EVT_MSGDEAD,
txtMsg.getJMSCorrelationID(), MIBConstants.DLQREASON,
MIBConstants.DLQREASON_REQQ);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
}

Thanks a lot in advance..

Manav.
-- 
View this message in context: http://www.nabble.com/Expired-Message-Listener-tf3270915s2354.html#a9094216
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Mime
View raw message