activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chenq <chenq.m...@gmail.com>
Subject Re: why queue consumer threads only get half messages ?
Date Tue, 21 Oct 2008 12:31:02 GMT

I start consumers threads first, and then start producers, and producers is
keeping sending messages during consumers receives, so the queue is not
empty. 
At last, when I calculate the total number of the receiving and sending
messages, they doesn't match.


James.Strachan wrote:
> 
> Is this FAQ entry applicable?
> http://activemq.apache.org/i-do-not-receive-messages-in-my-second-consumer.html
> 
> 2008/10/21 chenq <chenq.mail@gmail.com>:
>>
>>  I'm testing the activemq, and when I make my cosumers receive messages
>> from
>> a queue in multi-threds , it only get half messages sent from producers.
>> would somebody can tell me why?
>>
>>
>> here is my source code:
>>
>> public class Recv extends Thread {
>>    private static final String url = "tcp://localhost:61616";
>>    private static final String QUEUE_NAME = "TestQue";
>>    private static final String TOPIC_NAME = "TestTopic";
>>    public static int mode = 0;
>>
>>    public void revceMessage() throws JMSException {
>>        Connection connection = null;
>>        TextMessage ms = null;
>>        StringBuffer str = null;
>>        int i = 0;
>>        try {
>>            ActiveMQConnectionFactory connectionFactory = new
>> ActiveMQConnectionFactory(url);
>>            connection = connectionFactory.createConnection();
>>            connection.start();
>>            Session session = connection.createSession(false,
>> Session.AUTO_ACKNOWLEDGE);
>>            Destination destination = null;
>>            if(mode == 0)
>>                destination = session.createQueue(QUEUE_NAME);
>>            else
>>                destination = session.createTopic(TOPIC_NAME);
>>            MessageConsumer consu = session.createConsumer(destination,
>> null);
>>            while (true) {
>>                ms = (TextMessage) consu.receive();
>>                i++;
>>                if (ms == null) {
>>                    break;
>>                }
>>                str = new StringBuffer();
>>                str.append("thread:");
>>                str.append(this.getId());
>>                str.append(",receive:");
>>                str.append(i);
>>                System.out.println(str);
>>                str = null;
>>            }
>>
>>        }
>>        catch (Exception e) {
>>            e.printStackTrace();
>>        } finally {
>>            if (connection != null) {
>>                connection.close();
>>            }
>>        }
>>    }
>>
>>    public void run() {
>>        try {
>>                this.revceMessage();
>>        } catch (JMSException e) {
>>                e.printStackTrace();
>>        }
>>    }
>>
>>    public static void main(String[] args) {
>>        Recv s = null;
>>        if ((args.length >0) && (!args[0].trim().equals("0")))
>>                mode = 1;
>>        System.out.println("mode is: " + mode + ", url:" + url);
>>        for(int i=0;i<2;i++) {
>>                s = new Recv();
>>                s.start();
>>        }
>>    }
>> }
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/why-queue-consumer-threads-only-get-half-messages---tp20088895p20088895.html
>> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>>
>>
> 
> 
> 
> -- 
> James
> -------
> http://macstrac.blogspot.com/
> 
> Open Source Integration
> http://fusesource.com/
> 
> 

-- 
View this message in context: http://www.nabble.com/why-queue-consumer-threads-only-get-half-messages---tp20088895p20089158.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Mime
View raw message