You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by chenq <ch...@gmail.com> on 2008/10/21 14:11:31 UTC

why queue consumer threads only get half messages ?

 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.


Re: why queue consumer threads only get half messages ?

Posted by chenq <ch...@gmail.com>.
no,there is only my consumers for that queue.


James.Strachan wrote:
> 
> 2008/10/21 chenq <ch...@gmail.com>:
>>
>> 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.
> 
> Try looking in the web console / JMX - do you see any other consumers?
> 
> -- 
> 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---tp20088895p20091627.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: why queue consumer threads only get half messages ?

Posted by James Strachan <ja...@gmail.com>.
2008/10/21 chenq <ch...@gmail.com>:
>
> 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.

Try looking in the web console / JMX - do you see any other consumers?

-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://fusesource.com/

Re: why queue consumer threads only get half messages ?

Posted by chenq <ch...@gmail.com>.
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 <ch...@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.


Re: why queue consumer threads only get half messages ?

Posted by James Strachan <ja...@gmail.com>.
Is this FAQ entry applicable?
http://activemq.apache.org/i-do-not-receive-messages-in-my-second-consumer.html

2008/10/21 chenq <ch...@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/

Re: why queue consumer threads only get half messages ?

Posted by chenq <ch...@gmail.com>.
yes, there is only one broker. I just simply extract the activemq with
default configuration


Joe Fernandez wrote:
> 
> Is their only one broker in your configuration? 
> 
> Joe
> http://www.ttmsolutions.com - get a free ActiveMQ user guide
> 
> 
> 
> 
> chenq wrote:
>> 
>>  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---tp20088895p20100924.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: why queue consumer threads only get half messages ?

Posted by Joe Fernandez <jo...@ttmsolutions.com>.
Is their only one broker in your configuration? 

Joe
http://www.ttmsolutions.com - get a free ActiveMQ user guide




chenq wrote:
> 
>  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---tp20088895p20092449.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: why queue consumer threads only get half messages ?

Posted by Joe Fernandez <jo...@ttmsolutions.com>.
Is there only one broker in your configuration? 

Joe
http://www.ttmsolutions.com - get a free ActiveMQ user guide


chenq wrote:
> 
>  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---tp20088895p20092457.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.