activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serious <>
Subject Re: Keeping the messages in a queue or topic during a day
Date Mon, 13 Jun 2011 08:53:03 GMT
Thanks a lot Mr Tully, this is the right solution.

So, to sum up :
- you first have to configure the broker by tweaking its "conf/activemq.xml"
configuration file :
<?xml version="1.0" encoding="UTF-8"?>
	<broker ...>
					<policyEntry topic="tests.retro.>" producerFlowControl="true"
								<timedSubscriptionRecoveryPolicy recoverDuration="3600000" />
The "recoverDuration" is expressed in ms, so here the duration is 1 hour.

- then you should be able to use retroactive consumers (some C#/NMS sample)
string retroactiveTopicName = "tests.retro.test_" + Guid.NewGuid() +

ConnectionFactory connectionFactory = new

var producerConnection = connectionFactory.CreateConnection();

var producerSession = (Session)producerConnection.CreateSession();

var producer = producerSession.CreateProducer();

var message = producer.CreateTextMessage("First message!");

producer.Send(producerSession.GetTopic(retroactiveTopicName), message);

message = producer.CreateTextMessage("Second message!");

producer.Send(producerSession.GetTopic(retroactiveTopicName), message);

var consumerConnection = connectionFactory.CreateConnection();

var consumersSession = (Session)consumerConnection.CreateSession();

var retroactiveConsumer =
+ "?consumer.retroactive=true"));
retroactiveConsumer.Listener += incomingMessage =>
	Console.WriteLine("Retroactive consumer in : {0}!", (incomingMessage as

var nonRetroactiveConsumer =
nonRetroactiveConsumer.Listener += incomingMessage =>
	Console.WriteLine("Non retroactive consumer in : {0}!", (incomingMessage as

message = producer.CreateTextMessage("Third message!");

producer.Send(producerSession.GetTopic(retroactiveTopicName), message);

System.Console.Write("Press enter to exit...");

Notice the "?consumer.retroactive=true" appended to the name of the topic to
make the current consumer retroactive.

Only the retroactive consumer should receive the three messages, the other
one only the third one.

Hopefully this will help somebody else.

Thanks all for your precious help.

View this message in context:
Sent from the ActiveMQ - User mailing list archive at

View raw message