Bugs item #835234, was opened at 2003-11-03 20:44 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=376685&aid=835234&group_id=22866
Category: JBossMQ Group: v3.2 Status: Open Resolution: None Priority: 5 Submitted By: Sverker Abrahamsson (sverkera) Assigned to: Nobody/Anonymous (nobody) Summary: Wrong behaviour with multiple listeners to a queue Initial Comment: I wanted to have messages distibruted to multiple listeners from one queue but no matter how many listeners I added, it was always the first and occationally the second that were given all the messages. I asked in the forum in thread http://www.jboss.org/thread.jsp? forum=48&thread=36553 about this and eventually I found out the answer. The answer is to replace "HashSet receivers = new HashSet();" in org.jboss.mq.server.BasicQueue with "LinkedList receivers = new LinkedList();" Changing to LinkedList gave the expected behaviour, messages are now distributed evenly to all listeners. The reason for that is explained in the text below which I've copied from the thread. I've been running the server with this patch for a couple of months now and it works excellent. (Below is text copied from the thread) BasicQueue keeps the waiting receivers in a HashSet and when it gets a messag, it calls the internalAddMessage method which iterates through the receivers and picks the first subscription that matches the headers of the message and pass the message on to it's ClientConsumer instance. After that it removes that subscription from the receivers. The ClientConsumer passes the message on through the registered ClientIL to a Connection's asyncDeliver method. It is then passed on to a SpyConsumer instance with the addMessage method. In my case that is a SpyMessageConsumer which puts the message in a LinkedList. A thread then picks it from the LinkedList and call the onMessage method on my listener. I haven't found out exactly how yet but when the ClientConsumer has delivered the message it's subscription is added again to the receivers in BasicQueue. receivers is a HashSet instance and it's implementation uses a HashMap to store it's entries in the HashMap key. HashMap keys are stored in an array and when a new key/value pair (the value is null in this case) is added, the array is searched for the first empty position in the array, which happens to be the first position since that is the one where the key were removed by the iterator in BasicQueue.internalAddMessage. This means that the order of the subscriptions is maintained more or less to be the same as when they were registered the first time. internalAddMessage picks the first subscription and the only time it will pick the second subscription is when it receives a message before the first subscription has finished processing the previous message. ClientConsumer uses a thread pool so it looks like that the thread that calls it from BasicQueue just drops it of on a thread from the pool and returns so most of the times the first subscription process the messages as fast as they arrive so it's only in a few cases the second subscriber get used. That means that most of the messages ends up in the LinkedList of the SpyMessageConsumer to which my first listeners is registered. The second listener receives a few and the rest of them receives nothing.. The behaviour I expected was that the messages would be evenly between the listeners, I think that is logica. That behaviour should be acomplished by changing the receivers in BasicQueue from a HashSet to a LinkedList, then the subscriber that has finished is added to the end of the list and have to wait until last. I'll test that and see what happens. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=376685&aid=835234&group_id=22866 ------------------------------------------------------- This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/ _______________________________________________ JBoss-Development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
