Thank you for the suggestion. I created AMQ-3436 for this issue.
https://issues.apache.org/jira/browse/AMQ-3436
I attached my JUNIT test case and the patched files.
I modified the code to use the existing PendingList (PrioritiziedPendingList or OrderedPendingList depending on if prioritization is enabled) structure to hold the messages that are waiting to be dispatched.
From: Gary Tully [via ActiveMQ] [mailto:ml-node+3713800-2029387266-139195@n4.nabble.com]
Sent: Tuesday, August 02, 2011 5:15 PM
To: Urciolo, Kevin J (IS)
Subject: Re: EXT :Re: Message Priority In 5.5.0-fuse-00-43
If you can build a simple junit test case that is fixed with your
changes please submit it as a patch via a new jira issue (a file
attachment in jira allows you to do a license grant). All
contributions are most welcome.
The test case is key as it will ensure your use case is captured and
protected into the future. It will also help frame your changes.
On 2 August 2011 20:34, urciolo > wrote:
> I am not very familiar with the ActiveMQ source. I made a simple modification to the Queue.java source to sort just prior to dispatch to get the desired behavior as an experiment. There are more efficient ways to handle the prioritization, but this method isolates the changes to one location (to prevent me from breaking something).
>
> I see prioritization in the code in other area, such as the PrioritizedPendingList class. I am not sure if that interacts with the messages pending dispatch in any way. I could not see an interaction.
>
> Kevin
>
>
> From: Urciolo, Kevin J (IS)
> Sent: Friday, July 29, 2011 11:58 AM
> To: 'Gary Tully [via ActiveMQ]'
> Subject: RE: EXT :Re: Message Priority In 5.5.0-fuse-00-43
>
> I changed from a listener to a consumer.receive and set the prefetch to 0. The behavior is the same as with the message listener and prefetch set to 1.
>
>
> From: Gary Tully [via ActiveMQ] [mailto:[hidden email]]
> Sent: Thursday, July 28, 2011 6:17 PM
> To: Urciolo, Kevin J (IS)
> Subject: Re: EXT :Re: Message Priority In 5.5.0-fuse-00-43
>
> if you use prefetch=0, do you still see that behavior?
>
> On 28 July 2011 21:07, urciolo > wrote:
>
>> Hello, I took a look at the test cases. I modified one a bit to reproduce the behavior I am seeing. It seems if “createConsumer” is called prior to the producer sending messages, then prioritization does not work correctly. If I simply move the createConsumer statement to below the producer sending messages, then they are consumed in priority order. The example code is attached too.
>>
>> This is a problem for us since we want our consumers attached an listening all the time for messages. This behavior is reproducible with the JAVA and CMS clients (Openwire).
>>
>> Do you have suggestions on what section of code I can look to attempt to track down the problem?
>>
>> // Create producer
>> ActiveMQConnection producerConnection = (ActiveMQConnection) cf.createConnection();
>> producerConnection.setMessagePrioritySupported(true);
>> producerConnection.start();
>> final Session producerSession = producerConnection.createSession(true, Session.SESSION_TRANSACTED);
>> MessageProducer producer = producerSession.createProducer(dest);
>>
>> // Create consumer on separate connection
>> ActiveMQConnection consumerConnection = (ActiveMQConnection) cf.createConnection();
>> consumerConnection.setMessagePrioritySupported(true);
>> consumerConnection.start();
>> final ActiveMQSession consumerSession = (ActiveMQSession) consumerConnection.createSession(true, Session.SESSION_TRANSACTED);
>>
>> //***************************************************
>> // If we create the consumer here, the
>> // the messages will be consumed in FIFO like order
>> //***************************************************
>> ActiveMQMessageConsumer consumer = (ActiveMQMessageConsumer) consumerSession.createConsumer(dest);
>>
>> // Produce X number of messages with a session commit after each message
>> Random random = new Random();
>> for (int i = 0; i < messageCount; ++i) {
>>
>> Message message = producerSession.createTextMessage("Test message #" + i);
>> producer.send(message, DeliveryMode.PERSISTENT, random.nextInt(10), 5000);
>> producerSession.commit();
>> }
>> producer.close();
>>
>> //***************************************************
>> // If we create the consumer here instead of above, the
>> // the messages will be consumed in priority order
>> //***************************************************
>> //ActiveMQMessageConsumer consumer = (ActiveMQMessageConsumer) consumerSession.createConsumer(dest);
>>
>>
>>
>> From: Gary Tully [via ActiveMQ] [mailto:[hidden email]]
>> Sent: Tuesday, July 26, 2011 3:39 PM
>> To: Urciolo, Kevin J (IS)
>> Subject: Re: EXT :Re: Message Priority In 5.5.0-fuse-00-43
>>
>> so that is not expected. Have a peek over one of the message priority
>> test cases to see if there is something different from your scenario,
>> you need to enable priority support on a destination for example.
>>
>> Also note that kahaDB supports three priority levels, and the jdbc store 0-9.
>> http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/store/MessagePriorityTest.java?view=markup
>>
>> On 26 July 2011 18:48, urciolo > wrote:
>>
>>> Thank you for the prompt reply.
>>>
>>> We do have prefetch set to 1. This test was with a single producer that produced all the messages that was then followed by a consumer to consume all the messages. Screenshot of consumer prefetch attached.
>>>
>>>
>>> From: Gary Tully [via ActiveMQ] [mailto:[hidden email]]
>>> Sent: Tuesday, July 26, 2011 1:38 PM
>>> To: Urciolo, Kevin J (IS)
>>> Subject: EXT :Re: Message Priority In 5.5.0-fuse-00-43
>>>
>>> if you have concurrent producers and consumers, then the prefetch has
>>> an effect as a consumer will get a batch of messages which will get
>>> delivered with relative priority.. but there may be others with higher
>>> priority arriving on the broker.
>>> Use prefetch=1|0 to circumvent that.
>>>
>>> On 26 July 2011 18:18, urciolo > wrote:
>>>
>>>> I am testing out message priority in 5.5.0-fuse-00-43.
>>>>
>>>> I have prioritization enabled, and a maxPageSize of 5000. When I consume
>>>> 230 messages with priorities 0-9, almost all of them are consumed in the
>>>> correct priority. However, the last 20 or so seem to start the priority
>>>> consumption over again. I thought increasing the maxPageSize would fix this
>>>> problem. However, it does not seem to make a difference. Is this the
>>>> expected behavior?
>>>>
>>>> Attached is a text file showing the consumption of messages. The payload
>>>> output is the priority number. You can see at the end how the priorities
>>>> start over again.
>>>>
>>>>
>>>> http://activemq.2283324.n4.nabble.com/file/n3696416/test2.txt test2.txt
>>>>
>>>>
>>>> http://activemq.2283324.n4.nabble.com/file/n3696416/attributes.jpg
>>>>
>>>> --
>>>> View this message in context: http://activemq.2283324.n4.nabble.com/Message-Priority-In-5-5-0-fuse-00-43-tp3696416p3696416.html
>>>> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>>>>
>>>
>>>
>>>
>>> --
>>> http://fusesource.com
>>> http://blog.garytully.com
>>>
>>> ________________________________
>>> If you reply to this email, your message will be added to the discussion below:
>>>
>>>
>>>
>>> --
>>> View this message in context: http://activemq.2283324.n4.nabble.com/Message-Priority-In-5-5-0-fuse-00-43-tp3696416p3696505.html
>>> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>>
>>
>>
>> --
>> http://fusesource.com
>> http://blog.garytully.com
>>
>> ________________________________
>> If you reply to this email, your message will be added to the discussion below:
>>
>>
>>
>> --
>> View this message in context: http://activemq.2283324.n4.nabble.com/Message-Priority-In-5-5-0-fuse-00-43-tp3696416p3702365.html
>> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
>
>
> --
> http://fusesource.com
> http://blog.garytully.com
> ________________________________
> If you reply to this email, your message will be added to the discussion below:
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/Message-Priority-In-5-5-0-fuse-00-43-tp3696416p3713504.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
--
http://fusesource.com
http://blog.garytully.com
________________________________
If you reply to this email, your message will be added to the discussion below:
http://activemq.2283324.n4.nabble.com/Message-Priority-In-5-5-0-fuse-00-43-tp3696416p3713800.html
To unsubscribe from Message Priority In 5.5.0-fuse-00-43, click here.
--
View this message in context: http://activemq.2283324.n4.nabble.com/Message-Priority-In-5-5-0-fuse-00-43-tp3696416p3716778.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.