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 :
[code]
<?xml version="1.0" encoding="UTF-8"?>
<beans...>
        <broker ...>
                <destinationPolicy>
                        <policyMap>
                                <policyEntries>
                                        ...
                                        <policyEntry topic="tests.retro.>" 
producerFlowControl="true"
memoryLimit="1mb">
                                                        
<subscriptionRecoveryPolicy>
                                                                
<timedSubscriptionRecoveryPolicy recoverDuration="3600000" />
                                                        
</subscriptionRecoveryPolicy>
                                        </policyEntry>
                                </policyEntries>
                        </policyMap>
                </destinationPolicy>
        </broker>
        ...
</beans>
[/code]
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)
:
[code]
string retroactiveTopicName = "tests.retro.test_" + Guid.NewGuid() +
".topic";

ConnectionFactory connectionFactory = new
ConnectionFactory("tcp://localhost:61616");

var producerConnection = connectionFactory.CreateConnection();
producerConnection.Start();

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();
consumerConnection.Start();

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

var retroactiveConsumer =
(MessageConsumer)consumersSession.CreateConsumer(consumersSession.GetTopic(retroactiveTopicName
+ "?consumer.retroactive=true"));
retroactiveConsumer.Listener += incomingMessage =>
{
        Console.WriteLine("Retroactive consumer in : {0}!", (incomingMessage as
ITextMessage).Text);
};

var nonRetroactiveConsumer =
(MessageConsumer)consumersSession.CreateConsumer(consumersSession.GetTopic(retroactiveTopicName));
nonRetroactiveConsumer.Listener += incomingMessage =>
{
        Console.WriteLine("Non retroactive consumer in : {0}!", 
(incomingMessage as
ITextMessage).Text);
};

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

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

System.Console.Write("Press enter to exit...");
System.Console.ReadLine();
[/code]

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: 
http://activemq.2283324.n4.nabble.com/Keeping-the-messages-in-a-queue-or-topic-during-a-day-tp3561343p3593408.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Reply via email to