You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@activemq.apache.org by caesarkim <ca...@hotmail.com> on 2007/12/11 21:00:04 UTC

ERROR: The Consumer is closed

I have a jms client consuming a message from queue in the activeMQ, but for
some reason, it hangs and throws the following error. I am using ActiveMQ
4.1.  My JMS client is using multiple connections. 

here is pseudo code.
JMSClient extends Thread
{
   public void run()
   {
       ActiveMQConnectionFactory factory = ...
       Connection conn = factory.createQueueConnection();
       QueueSession session = conn.createQueueSession();
       QueueReceiver receiver = session.createReceiver(queue);
       while(true)
       {
            Message m = receiver.receive(1);
            // Receiving a message.
       }


   }
}

for(int i = 0; i < 10; i++)
{
     new JMSClient().start();
}



IllegalStateException: The Consumer is closed at
org.apache.activemq.ActiveMQMessageConsumer.checkClosed(ActiveMQMessageConsumer.java:672)

Does anybody know why it is thrown and how to prevent this error?  

Please correct this if i am using the jms client in a wrong way for
multi-threading.

I am new to the activeMQ.

Thanks.

-- 
View this message in context: http://www.nabble.com/ERROR%3A-The-Consumer-is-closed-tp14282085s2354p14282085.html
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.


Re: ERROR: The Consumer is closed

Posted by Albert Strasheim <fu...@gmail.com>.
Hello

On Tue, 11 Dec 2007, caesarkim wrote:

> I have a jms client consuming a message from queue in the activeMQ, but for
> some reason, it hangs and throws the following error. I am using ActiveMQ
> 4.1.  My JMS client is using multiple connections. 
> 
> here is pseudo code.
> JMSClient extends Thread
> {
>    public void run()
>    {
>        ActiveMQConnectionFactory factory = ...
>        Connection conn = factory.createQueueConnection();

I don't have the JMS spec handy, but I think the problem is probably 
being caused by this line. I don't think the connection factory is 
guaranteed to be thread safe.

>        QueueSession session = conn.createQueueSession();
>        QueueReceiver receiver = session.createReceiver(queue);
>        while(true)
>        {
>             Message m = receiver.receive(1);
>             // Receiving a message.
>        }
> 
> 
>    }
> }
> 
> for(int i = 0; i < 10; i++)
> {
>      new JMSClient().start();
> }
> 
> 
> 
> IllegalStateException: The Consumer is closed at
> org.apache.activemq.ActiveMQMessageConsumer.checkClosed(ActiveMQMessageConsumer.java:672)
> 
> Does anybody know why it is thrown and how to prevent this error?  
> 
> Please correct this if i am using the jms client in a wrong way for
> multi-threading.

If I remember correctly, the JMS 1.1 specification says that you can 
share a connection between threads, but that a session should only be 
used in a single thread at any given time.

So you can do:

ConnectionFactory factory = ...;
for (...) {
    // connection per thread
    new JMSClient(factory.createConnection()).start();
}

or:

ConnectionFactory factory = ...;
// single connection shared by all threads
Connection conn = factory.createConnection();
for (...) {
    new JMSClient(conn).start();
}

or 

ConnectionFactory factory = ...;
Connection conn = factory.createConnection();
for (...) {
    new JMSClient(conn.createSession()).start();
}

I'm pretty sure the last one will work. The others might work, but I 
don't have the JMS spec to check if they should.

Hope that helps.

Cheers,

Albert

Re: ERROR: The Consumer is closed

Posted by Rob Davies <ra...@gmail.com>.
On Dec 11, 2007, at 8:00 PM, caesarkim wrote:

>
> I have a jms client consuming a message from queue in the activeMQ,  
> but for
> some reason, it hangs and throws the following error. I am using  
> ActiveMQ
> 4.1.  My JMS client is using multiple connections.
>
> here is pseudo code.
> JMSClient extends Thread
> {
>   public void run()
>   {
>       ActiveMQConnectionFactory factory = ...
>       Connection conn = factory.createQueueConnection();
>       QueueSession session = conn.createQueueSession();
>       QueueReceiver receiver = session.createReceiver(queue);
>       while(true)
>       {
>            Message m = receiver.receive(1);
>            // Receiving a message.
>       }
>
>
>   }
> }
>
> for(int i = 0; i < 10; i++)
> {
>     new JMSClient().start();
> }
>
>
>
> IllegalStateException: The Consumer is closed at
> org 
> .apache 
> .activemq 
> .ActiveMQMessageConsumer.checkClosed(ActiveMQMessageConsumer.java:672)
>
> Does anybody know why it is thrown and how to prevent this error?
>
> Please correct this if i am using the jms client in a wrong way for
> multi-threading.
>
> I am new to the activeMQ.
>
> Thanks.
>
> -- 
> View this message in context: http://www.nabble.com/ERROR%3A-The-Consumer-is-closed-tp14282085s2354p14282085.html
> Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.
>

Doesn't look like you're calling start on the Connection before  
calling receive



Rob Davies
'Go further faster with Apache Camel!'
http://rajdavies.blogspot.com/