You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by serious <se...@orange.fr> on 2011/06/01 10:15:24 UTC

Re: Keeping the messages in a queue or topic during a day

I guess this silence means : "No, there is no way to do that with ActiveMQ"
:)

So, do you know any other tool that could fit the above needs, without
having to implement a new one from scratch ?

Thanks in advance.

--
View this message in context: http://activemq.2283324.n4.nabble.com/Keeping-the-messages-in-a-queue-or-topic-during-a-day-tp3561343p3565219.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Keeping the messages in a queue or topic during a day

Posted by serious <se...@orange.fr>.
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.

Re: Keeping the messages in a queue or topic during a day

Posted by Gary Tully <ga...@gmail.com>.
have a peek at the tests:

http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/test/retroactive/

you need to configure a recovery policy on the destinations via the
broker xml configuration. the default policy is to not hold on to any
messages.

On 6 June 2011 11:53, serious <se...@orange.fr> wrote:
> @Gary : thanks for the pointer, this looks like the ideal solution.
>
> But I can't make it work, here is some code that does not work as expected :
> (Note : this is some C# using the NMS API but this is very close to
> Java+JMS)
>
> [code]// Generate a new unique topic name
> string retroactiveTopicName = "testRetro_" + 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!");
>
> // Send a first message
> producer.Send(producerSession.GetTopic(retroactiveTopicName), message);
>
> message = producer.CreateTextMessage("Second message!") as
> ActiveMQTextMessage;
>
> // Send a second message
> producer.Send(producerSession.GetTopic(retroactiveTopicName), message);
>
> var consumerConnection = connectionFactory.CreateConnection();
> consumerConnection.Start();
>
> var consumerSession = (Session)consumerConnection.CreateSession();
>
> var consumer =
> (MessageConsumer)consumerSession.CreateConsumer(consumerSession.GetTopic(retroactiveTopicName
> + "?consumer.retroactive=true"));
> // Wait for incoming messages
> consumer.Listener += incomingMessage =>
> {
>        Console.WriteLine("Consumer in : {0}!", (incomingMessage as
> ITextMessage).Text);
> };
>
> message = producer.CreateTextMessage("Third message!");
>
> // Send a third message
> producer.Send(producerSession.GetTopic(retroactiveTopicName), message);
>
> System.Console.Write("Press enter to exit...");
> System.Console.ReadLine();[/code]
>
> The producer sends three messages : two before the consumer is connected,
> one after.
> But the consumer only receives the third one, so the "retroactive" flag
> seems to be completely ignored.
>
> What am I doing wrong ?
>
> Thanks.
>
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/Keeping-the-messages-in-a-queue-or-topic-during-a-day-tp3561343p3576662.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>



-- 
http://fusesource.com
http://blog.garytully.com

Re: Keeping the messages in a queue or topic during a day

Posted by serious <se...@orange.fr>.
@Gary : thanks for the pointer, this looks like the ideal solution.

But I can't make it work, here is some code that does not work as expected :
(Note : this is some C# using the NMS API but this is very close to
Java+JMS)

[code]// Generate a new unique topic name
string retroactiveTopicName = "testRetro_" + 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!");

// Send a first message
producer.Send(producerSession.GetTopic(retroactiveTopicName), message);

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

// Send a second message
producer.Send(producerSession.GetTopic(retroactiveTopicName), message);

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

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

var consumer =
(MessageConsumer)consumerSession.CreateConsumer(consumerSession.GetTopic(retroactiveTopicName
+ "?consumer.retroactive=true"));
// Wait for incoming messages
consumer.Listener += incomingMessage =>
{
	Console.WriteLine("Consumer in : {0}!", (incomingMessage as
ITextMessage).Text);
};

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

// Send a third message
producer.Send(producerSession.GetTopic(retroactiveTopicName), message);

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

The producer sends three messages : two before the consumer is connected,
one after.
But the consumer only receives the third one, so the "retroactive" flag
seems to be completely ignored.

What am I doing wrong ?

Thanks.

--
View this message in context: http://activemq.2283324.n4.nabble.com/Keeping-the-messages-in-a-queue-or-topic-during-a-day-tp3561343p3576662.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Keeping the messages in a queue or topic during a day

Posted by Gary Tully <ga...@gmail.com>.
Silence typically means folks are busy!
Have a look at http://activemq.apache.org/retroactive-consumer.html
and http://activemq.apache.org/subscription-recovery-policy.html


On 1 June 2011 09:15, serious <se...@orange.fr> wrote:
> I guess this silence means : "No, there is no way to do that with ActiveMQ"
> :)
>
> So, do you know any other tool that could fit the above needs, without
> having to implement a new one from scratch ?
>
> Thanks in advance.
>
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/Keeping-the-messages-in-a-queue-or-topic-during-a-day-tp3561343p3565219.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>



-- 
http://fusesource.com
http://blog.garytully.com