You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by manav <vy...@yahoo.com> on 2007/02/22 05:22:29 UTC

Expired Message Listener

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.


Re: [Spam: 5.0] Expired Message Listener

Posted by rajdavies <ra...@gmail.com>.
This doesn't work correctly in 4.x at the moment. Please could you raise a
jira issue for it

cheers,

Rob


manav wrote:
> 
> 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#a9123822
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: [Spam: 5.0] Expired Message Listener

Posted by Sheetal <Sh...@sungard.com>.
I have set up individual dead letter strategy, however still it sends the 
message to "ActiveMQ.DLQ" and not to individual DLQ queue. please guide




Re: [Spam: 5.0] Expired Message Listener

Posted by "Christopher G. Stach II" <cg...@ldsys.net>.
Vadim Pesochinsky wrote:
> You do not need to set it up, if queue does not exist when you connect to it,
> it will be created. I think by default the <sharedDeadLetterStrategy> is
> used, i.e. all expired messages from all queues go to the same ActiveMQ.DLQ
> queue.

The individual strategy has this nice feature where it changes the
JMSDestination to the DLQ's name.  If shared does that, you won't know
(by headers) what the original destination was.  Then you can't use the
JMX message selectors to requeue, etc.

-- 
Christopher G. Stach II


Re: [Spam: 5.0] Expired Message Listener

Posted by Vadim Pesochinsky <Va...@mscibarra.com>.
You do not need to set it up, if queue does not exist when you connect to it,
it will be created. I think by default the <sharedDeadLetterStrategy> is
used, i.e. all expired messages from all queues go to the same ActiveMQ.DLQ
queue.
-- 
View this message in context: http://www.nabble.com/Expired-Message-Listener-tf3270915s2354.html#a9124501
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: [Spam: 5.0] Expired Message Listener

Posted by "Christopher G. Stach II" <cg...@ldsys.net>.
manav wrote:
> Thanks for this message..   Could you please elaborate on this..
> 
> Do we need to setup a queue named "ActiveMQ.DLQ" and point all our
> destinations that could have messages expired to the "ActiveMQ.DLQ" queue?
> Do you have any specific pointers / examples for this?
> 
> Appreciate any help...
> 
> Manav 
> 
> 
> Vadim Pesochinsky wrote:
>> I think you can use JMS api, the queue name is "ActiveMQ.DLQ" if I
>> remember correctly.
>>
> 

http://www.google.com/search?q=site%3Aactivemq.org+deadletterstrategy

-- 
Christopher G. Stach II


Re: [Spam: 5.0] Expired Message Listener

Posted by manav <vy...@yahoo.com>.
Thanks for this message..   Could you please elaborate on this..

Do we need to setup a queue named "ActiveMQ.DLQ" and point all our
destinations that could have messages expired to the "ActiveMQ.DLQ" queue?
Do you have any specific pointers / examples for this?

Appreciate any help...

Manav 


Vadim Pesochinsky wrote:
> 
> I think you can use JMS api, the queue name is "ActiveMQ.DLQ" if I
> remember correctly.
> 

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


Re: [Spam: 5.0] Expired Message Listener

Posted by Vadim Pesochinsky <Va...@mscibarra.com>.
I think you can use JMS api, the queue name is "ActiveMQ.DLQ" if I remember
correctly.
-- 
View this message in context: http://www.nabble.com/Expired-Message-Listener-tf3270915s2354.html#a9111825
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: [Spam: 5.0] Expired Message Listener

Posted by James Strachan <ja...@gmail.com>.
Use the 4.2-SNAPSHOT, not the 4.2-incubator-SNAPSHOT. (Now that we
have graduated from the Incubator we no longer use incubator in
version numbers)


On 2/23/07, manav <vy...@yahoo.com> wrote:
>
> Any ideas if this is fixed in any latest development build? I see a
> 4.2-SNAPSHOT and 4.2-incubator-snapshot under the 'source' link..  Not sure
> how 'incubator' build is different from the other one.. but am ready to try
> anything if it is fixed...
>
>
> Christopher G. Stach II wrote:
> >
> > manav wrote:
> >> Could someone pease respond back to the posted question?
> >>
> >> We are holding off a release as we cannot get (do not know how to get)
> >> message expiry to work in 4.1. This is critical to a big company using
> >> AMQ.
> >>
> >> Any immediate help / suggestion is appreciated.
> >>
> >> Manav
> >>
> >>
> >
> > I don't think expiration works in 4.1.
> >
> > --
> > Christopher G. Stach II
> >
> >
> >
>
> --
> View this message in context: http://www.nabble.com/Expired-Message-Listener-tf3270915s2354.html#a9123819
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
>


-- 

James
-------
http://radio.weblogs.com/0112098/

Re: [Spam: 5.0] Expired Message Listener

Posted by "Christopher G. Stach II" <cg...@ldsys.net>.
manav wrote:
> Any ideas if this is fixed in any latest development build? I see a
> 4.2-SNAPSHOT and 4.2-incubator-snapshot under the 'source' link..  Not sure
> how 'incubator' build is different from the other one.. but am ready to try
> anything if it is fixed...  
> 
> 
> Christopher G. Stach II wrote:
>> I don't think expiration works in 4.1.
>>
>> -- 
>> Christopher G. Stach II
>>
>>
>>
> 

I don't know if it is, but I think it's supposed to be.  Let us know. :)

-- 
Christopher G. Stach II


Re: [Spam: 5.0] Expired Message Listener

Posted by Rob Davies <ra...@gmail.com>.
This isn't fixed in 4.2 yet either  I'm afraid :(

On 23 Feb 2007, at 18:13, manav wrote:

>
> Any ideas if this is fixed in any latest development build? I see a
> 4.2-SNAPSHOT and 4.2-incubator-snapshot under the 'source' link..   
> Not sure
> how 'incubator' build is different from the other one.. but am  
> ready to try
> anything if it is fixed...
>
>
> Christopher G. Stach II wrote:
>>
>> manav wrote:
>>> Could someone pease respond back to the posted question?
>>>
>>> We are holding off a release as we cannot get (do not know how to  
>>> get)
>>> message expiry to work in 4.1. This is critical to a big company  
>>> using
>>> AMQ.
>>>
>>> Any immediate help / suggestion is appreciated.
>>>
>>> Manav
>>>
>>>
>>
>> I don't think expiration works in 4.1.
>>
>> -- 
>> Christopher G. Stach II
>>
>>
>>
>
> -- 
> View this message in context: http://www.nabble.com/Expired-Message- 
> Listener-tf3270915s2354.html#a9123819
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>


Re: [Spam: 5.0] Expired Message Listener

Posted by manav <vy...@yahoo.com>.
Any ideas if this is fixed in any latest development build? I see a
4.2-SNAPSHOT and 4.2-incubator-snapshot under the 'source' link..  Not sure
how 'incubator' build is different from the other one.. but am ready to try
anything if it is fixed...  


Christopher G. Stach II wrote:
> 
> manav wrote:
>> Could someone pease respond back to the posted question? 
>> 
>> We are holding off a release as we cannot get (do not know how to get)
>> message expiry to work in 4.1. This is critical to a big company using
>> AMQ.
>> 
>> Any immediate help / suggestion is appreciated.
>> 
>> Manav
>> 
>> 
> 
> I don't think expiration works in 4.1.
> 
> -- 
> Christopher G. Stach II
> 
> 
> 

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


Re: [Spam: 5.0] Expired Message Listener

Posted by "Christopher G. Stach II" <cg...@ldsys.net>.
manav wrote:
> Could someone pease respond back to the posted question? 
> 
> We are holding off a release as we cannot get (do not know how to get)
> message expiry to work in 4.1. This is critical to a big company using AMQ.
> 
> Any immediate help / suggestion is appreciated.
> 
> Manav
> 
> 

I don't think expiration works in 4.1.

-- 
Christopher G. Stach II


Re: [Spam: 5.0] Expired Message Listener

Posted by manav <vy...@yahoo.com>.
Could someone pease respond back to the posted question? 

We are holding off a release as we cannot get (do not know how to get)
message expiry to work in 4.1. This is critical to a big company using AMQ.

Any immediate help / suggestion is appreciated.

Manav



manav wrote:
> 
> 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#a9111016
Sent from the ActiveMQ - User mailing list archive at Nabble.com.