activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan" <>
Subject Re: LastImage-style topic
Date Wed, 31 May 2006 15:38:21 GMT
On 5/31/06, Kuppe <> wrote:
> Thanks James for the quick reply.
> I understand that they are two different topics. I was only trying to
> demonstrate the scenario that is interesting to me. Everytime that the
> client receives messages it is only receiving the most recent and none of
> the previously updated messages - somehow receive latest image.
> So after reading the MessageEvictionStrategy, it seems that i need to
> implement this interface and therefore implement the
> evictMessage(LinkedList) method. My implementation would receive a linked
> list of messages which are ordered by time, and i should return a
> MessageReference referencing a message that can be evicted. Is this correct?

Yes. See how it goes - it could be we could refactor the code a little
to make it easier to do exactly what you want.

> I assume then that this should be accompanied by a
> PendingMessageLimitStrategy which will force the MessageEvictionStrategy to
> be used. Is this correct?


The PendingMessageLimitStrategy is there to enable message limits
(i.e. to calculate the maximum message limit for a given subscription;
once that limit is > 0 then eviction will start to occur when a
particular subscription has more than this number of messages

To see more detail of how this works, see TopicSubscription

> I also assume then that i could implement my own PendingMessageLimitStrategy
> that would determine just how many messages are valid for all messages in
> the queue.

Yes - note that we are talking about non-durable topics here right.
Your use of the word "queue" was just a reference to the buffer of
messages to be sent to a single slow consumer on the topic right?

>  But the javadoc describes that the number returned from the
> getMaximumPendingMessageLimit is based on the messages currently in the
> message queue and is in excess of the prefetch size for the subscription.

So PendingMessageLimitStrategy just purely returns the high watermark
for a given subscription. e.g. if you use the
ConstantPendingMessageLimitStrategy (which is the most common) - its
just a constant you define in the XML config file - such as all
consumers have a maximum message limit of 1000

> Are both of these interfaces pluggable in the configuration?


>  If so, how do i
> plug in my own specific implementation. It seems the examples given show
> only an alias for the implementation class.

So all of the activemq.xml file is pluggable. Whenever there is a
custom tag that defines a bean, you can replace it with  some regular
Spring configuration.

So in this example - the <pendingMessageLimit> defines the property
"pendingMessageLimit" on the PolicyEntry and the
<constantPendingMessageLimitStrategy> tag defines a bean (of type

              <constantPendingMessageLimitStrategy limit="10"/>

so you could do this instead to use your own implementation class...

              <bean class="com.acme.Foo" xmlns="">
                 <property name="foo" value="bar"/>

Note the use of xmlns="" in there as the <broker> element is usually
in the activemq namespace and <bean> must be in no-namespace in XML.

> Still, it seems that it is not possible to configure a way of constantly
> overwriting the latest price with a new price in the message queue.

You just need to evict the old price first. If there is no old price
for the topic on the last price added, just evict the oldest one.

e.g. if you set the message limit to 1000 then you will have a
LinkedList of 1000 messages. When message 1001 is added, your
MessageEvictionStrategy will be called to find the message to evict -
so iterate through the list looking for a message on the same topic -
and evict that one first - or failing that evict the oldest one (the
first in the list).

The source code of OldestMessageWithLowestPriorityEvictionStrategy might help



View raw message