Return-Path: Delivered-To: apmail-activemq-users-archive@www.apache.org Received: (qmail 91649 invoked from network); 24 Jul 2008 09:11:49 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 24 Jul 2008 09:11:49 -0000 Received: (qmail 68045 invoked by uid 500); 24 Jul 2008 09:11:48 -0000 Delivered-To: apmail-activemq-users-archive@activemq.apache.org Received: (qmail 68023 invoked by uid 500); 24 Jul 2008 09:11:48 -0000 Mailing-List: contact users-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@activemq.apache.org Delivered-To: mailing list users@activemq.apache.org Received: (qmail 68012 invoked by uid 99); 24 Jul 2008 09:11:48 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 24 Jul 2008 02:11:48 -0700 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=SPF_PASS,WHOIS_MYPRIVREG X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of Sachindra.Nath@efi.com designates 192.68.228.100 as permitted sender) Received: from [192.68.228.100] (HELO smtp2.efi.com) (192.68.228.100) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 24 Jul 2008 09:10:52 +0000 Received: from smtp2.efi.com (127.0.0.1) by smtp2.efi.com (MlfMTA v3.2r9) id hh13ps0171ss for ; Thu, 24 Jul 2008 02:12:20 -0700 (envelope-from ) Received: from MAIL1.efi.com ([192.68.228.89]) by smtp2.efi.com (SonicWALL 6.1.1.9685) with ESMTP; Thu, 24 Jul 2008 02:12:20 -0700 Received: from fcexhub01.efi.internal ([10.3.12.16]) by MAIL1.efi.com with InterScan Message Security Suite; Thu, 24 Jul 2008 02:13:05 -0700 Received: from fcexbh02.efi.internal (10.3.12.13) by fcexhub01.efi.internal (10.3.12.16) with Microsoft SMTP Server id 8.1.278.0; Thu, 24 Jul 2008 02:10:56 -0700 Received: from blrexmb01.efi.internal ([10.208.32.10]) by fcexbh02.efi.internal with Microsoft SMTPSVC(6.0.3790.3959); Thu, 24 Jul 2008 02:10:55 -0700 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-Class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: RE: Exception occurred: javax.jms.IllegalStateException: Cannot synchronously receive a message when a MessageListener is set Date: Thu, 24 Jul 2008 14:40:52 +0530 Message-ID: <13B4D38ED7B116429C3A426A2C3998D905B1CE9B@blrexmb01.efi.internal> In-Reply-To: <18627931.post@talk.nabble.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Exception occurred: javax.jms.IllegalStateException: Cannot synchronously receive a message when a MessageListener is set thread-index: Acjta/af1SIEBGc0QB2VBTeliJq6BgAAD2og References: <18627640.post@talk.nabble.com> <18627931.post@talk.nabble.com> From: Sachindra Nath To: X-OriginalArrivalTime: 24 Jul 2008 09:10:55.0566 (UTC) FILETIME=[2DCC96E0:01C8ED6D] X-NDR: Signature X-Mlf-Version: 6.1.1.9685 X-Mlf-UniqueId: o200807240912200227986 X-Virus-Checked: Checked by ClamAV on apache.org You will need to start the connection for receiving messages. After = setting up your receiver, call connection.start(); consumer =3D session.createConsumer(destination); connection.start(); Message message1 =3D consumer.receive(1000); Read the jms api/a good book. I believe activemq is supposed to be logging warning messages for these cases, which I donot see in your logs. Which version are you working = with? Apart from that, I see a lot of errors in your error logs....that are = related to port in use issues (for port 1099). Correct them... -----Original Message----- From: skg [mailto:saurabh_garg05@infosys.com]=20 Sent: Thursday, July 24, 2008 2:32 PM To: users@activemq.apache.org Subject: Re: Exception occurred: javax.jms.IllegalStateException: Cannot synchronously receive a message when a MessageListener is set Hi, i made the changes u have mentioned but i am not receiving any message. = I am putting the output of the console for the producer and the consumer as = well. Producer console window rrrrrrr Jul 24, 2008 2:27:38 PM SimpleProducer main INFO: Destination name is MyQueue Jul 24, 2008 2:27:39 PM org.apache.activemq.broker.BrokerService start INFO: Using Persistence Adapter: AMQPersistenceAdapter(activemq-data\localhost) Jul 24, 2008 2:27:39 PM org.apache.activemq.broker.BrokerService = getBroker INFO: ActiveMQ null JMS Message Broker (localhost) is starting Jul 24, 2008 2:27:39 PM org.apache.activemq.broker.BrokerService = getBroker INFO: For help or more information please see: = http://activemq.apache.org/ Jul 24, 2008 2:27:39 PM = org.apache.activemq.broker.jmx.ManagementContext$1 run WARNING: Failed to start jmx connector: Cannot bind to URL [rmi://localhost:1099/jmxrmi]: javax.naming.CommunicationException [Root exception is java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is:=20 java.net.SocketException: Software caused connection abort: recv failed] Jul 24, 2008 2:27:39 PM = org.apache.activemq.store.amq.AMQPersistenceAdapter start INFO: AMQStore starting using directory: activemq-data\localhost Jul 24, 2008 2:27:39 PM org.apache.activemq.kaha.impl.KahaStore = initialize INFO: Kaha Store using data directory = activemq-data\localhost\kr-store\state Jul 24, 2008 2:27:39 PM = org.apache.activemq.store.amq.AMQPersistenceAdapter start INFO: Active data files: [1] Jul 24, 2008 2:27:39 PM org.apache.activemq.kaha.impl.KahaStore = initialize INFO: Kaha Store using data directory = activemq-data\localhost\kr-store\data Jul 24, 2008 2:27:39 PM org.apache.activemq.broker.BrokerService start INFO: ActiveMQ JMS Message Broker (localhost, ID:blrkec41498d-3757-1216889859509-0:0) started Jul 24, 2008 2:27:39 PM org.apache.activemq.broker.TransportConnector = start INFO: Connector vm://localhost Started Jul 24, 2008 2:27:40 PM SimpleProducer main INFO: Sending message: This is message 1 after the senderJul 24, 2008 2:27:40 PM org.apache.activemq.broker.TransportConnector stop INFO: Connector vm://localhost Stopped Jul 24, 2008 2:27:40 PM org.apache.activemq.broker.BrokerService stop INFO: ActiveMQ Message Broker (localhost, ID:blrkec41498d-3757-1216889859509-0:0) is shutting down Jul 24, 2008 2:27:40 PM org.apache.activemq.broker.BrokerService stop INFO: ActiveMQ JMS Message Broker (localhost, ID:blrkec41498d-3757-1216889859509-0:0) stopped The consumer console window Jul 24, 2008 2:30:23 PM org.apache.activemq.broker.BrokerService start INFO: Using Persistence Adapter: AMQPersistenceAdapter(activemq-data\localhost) Jul 24, 2008 2:30:23 PM org.apache.activemq.broker.BrokerService = getBroker INFO: ActiveMQ null JMS Message Broker (localhost) is starting Jul 24, 2008 2:30:23 PM org.apache.activemq.broker.BrokerService = getBroker INFO: For help or more information please see: = http://activemq.apache.org/ Jul 24, 2008 2:30:23 PM = org.apache.activemq.store.amq.AMQPersistenceAdapter start INFO: AMQStore starting using directory: activemq-data\localhost Jul 24, 2008 2:30:23 PM = org.apache.activemq.broker.jmx.ManagementContext$1 run WARNING: Failed to start jmx connector: Cannot bind to URL [rmi://localhost:1099/jmxrmi]: javax.naming.CommunicationException [Root exception is java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is:=20 java.net.SocketException: Software caused connection abort: recv failed] Jul 24, 2008 2:30:23 PM org.apache.activemq.kaha.impl.KahaStore = initialize INFO: Kaha Store using data directory = activemq-data\localhost\kr-store\state Jul 24, 2008 2:30:23 PM = org.apache.activemq.store.amq.AMQPersistenceAdapter start INFO: Active data files: [1] Jul 24, 2008 2:30:23 PM org.apache.activemq.kaha.impl.KahaStore = initialize INFO: Kaha Store using data directory = activemq-data\localhost\kr-store\data Jul 24, 2008 2:30:23 PM org.apache.activemq.broker.BrokerService start INFO: ActiveMQ JMS Message Broker (localhost, ID:blrkec41498d-3764-1216890023650-0:0) started Jul 24, 2008 2:30:24 PM org.apache.activemq.broker.TransportConnector = start INFO: Connector vm://localhost Started Jul 24, 2008 2:30:24 PM org.apache.activemq.broker.TransportConnector = stop INFO: Connector vm://localhost Stopped Jul 24, 2008 2:30:24 PM org.apache.activemq.broker.BrokerService stop INFO: ActiveMQ Message Broker (localhost, ID:blrkec41498d-3764-1216890023650-0:0) is shutting down Jul 24, 2008 2:30:24 PM org.apache.activemq.broker.BrokerService stop INFO: ActiveMQ JMS Message Broker (localhost, ID:blrkec41498d-3764-1216890023650-0:0) stopped Can u help me . skg wrote: >=20 > Hi, > I worked on a simple java programm which acts as the producer and the > consumer as well.Now i a want to do it with two seperate java = programm, > one acting as the consumer and the other one as producer. > While executing the consumer programm i am getting this exception. > Exception occurred: javax.jms.IllegalStateException: Cannot = synchronously > receive a message when a MessageListener is set > I am using Eclipse as development tool. I have attached the code for = the > producer and consumer as well. >=20 > The producer > import javax.jms.Connection; > import javax.jms.ConnectionFactory; > import javax.jms.Destination; > import javax.jms.JMSException; > import javax.jms.Message; > import javax.jms.MessageConsumer; > import javax.jms.MessageProducer; > import javax.jms.Session; > import javax.jms.TextMessage; > import javax.naming.Context; > import javax.naming.InitialContext; > import javax.naming.NamingException; >=20 > import org.apache.commons.logging.Log; > import org.apache.commons.logging.LogFactory; >=20 > public class SimpleProducer { > private static final Log LOG =3D LogFactory.getLog(SimpleProducer.class); >=20 > private SimpleProducer() { > } >=20 > /** > * @param args the destination name to send to and optionally, the > number of > * messages to send > * @throws InterruptedException=20 > */ > public static void main(String[] args) throws InterruptedException = { > System.out.println("rrrrrrr"); > Context jndiContext =3D null; > ConnectionFactory connectionFactory =3D null; > Connection connection =3D null; > Session session =3D null; > Destination destination =3D null; > MessageProducer producer =3D null; > String destinationName =3D null; > final int numMsgs; >=20 > /* if ((args.length < 1) || (args.length > 2)) { > LOG.info("Usage: java SimpleProducer > []"); > System.exit(1); > }*/ > destinationName =3D "MyQueue"; > LOG.info("Destination name is " + destinationName); > if (args.length =3D=3D 2) { > numMsgs =3D (new Integer(args[1])).intValue(); > } else { > numMsgs =3D 1; > } >=20 > /* > * Create a JNDI API InitialContext object > */ > try { > jndiContext =3D new InitialContext(); > } catch (NamingException e) { > LOG.info("Could not create JNDI API context: " + > e.toString()); > System.exit(1); > } >=20 > /* > * Look up connection factory and destination. > */ > try { > connectionFactory =3D > (ConnectionFactory)jndiContext.lookup("ConnectionFactory"); > destination =3D > (Destination)jndiContext.lookup(destinationName); > } catch (NamingException e) { > LOG.info("JNDI API lookup failed: " + e); > System.exit(1); > } >=20 > /* > * Create connection. Create session from connection; false = means > * session is not transacted. Create sender and text message. = Send > * messages, varying text slightly. Send end-of-messages = message. > * Finally, close connection. > */ > try { > connection =3D connectionFactory.createConnection(); > session =3D connection.createSession(false, > Session.AUTO_ACKNOWLEDGE); > producer =3D session.createProducer(destination); > TextMessage message =3D session.createTextMessage(); > for (int i =3D 0; i < numMsgs; i++) { > message.setText("This is message " + (i + 1)); > LOG.info("Sending message: " + message.getText()); > producer.send(message); > } >=20 > /* > * Send a non-text control message indicating end of = messages. > */ > producer.send(session.createMessage()); > System.out.println("after the sender"); > Thread.sleep(10000); >=20 > /*MessageConsumer consumer =3D null; > consumer =3D session.createConsumer(destination); > Message message1 =3D consumer.receive(1000); > TextMessage txtMsg =3D (TextMessage)message; > String msg =3D txtMsg.getText(); > System.out.println("Receiving"+msg);*/ > } catch (JMSException e) { > LOG.info("Exception occurred: " + e); > } finally { > if (connection !=3D null) { > try { > connection.close(); > } catch (JMSException e) { > } > } > } > } >=20 > } >=20 > The Consumer=20 >=20 > import javax.jms.Connection; > import javax.jms.ConnectionFactory; > import javax.jms.Destination; > import javax.jms.JMSException; > import javax.jms.Message; > import javax.jms.MessageConsumer; > import javax.jms.MessageListener; > import javax.jms.MessageProducer; > import javax.jms.Session; > import javax.jms.TextMessage; > import javax.naming.Context; > import javax.naming.InitialContext; > import javax.naming.NamingException; >=20 > import org.apache.commons.logging.Log; > import org.apache.commons.logging.LogFactory; >=20 > public class Consumer implements MessageListener{ > private static final Log LOG =3D LogFactory.getLog(Consumer.class); > Context jndiContext =3D null; > ConnectionFactory connectionFactory =3D null; > Connection connection =3D null; > Session session =3D null; > Destination destination =3D null,destination1; > MessageProducer producer =3D null; > String destinationName =3D null; > // final int numMsgs; > MessageConsumer consumer =3D null; > public static void main(String[] args) { > System.out.println("rrrrrrr"); > Consumer c=3Dnew Consumer(); > c.run(); > } > public void run() > { > destinationName =3D "MyQueue"; > try { > jndiContext =3D new InitialContext(); > } catch (NamingException e) { > LOG.info("Could not create JNDI API context: " + > e.toString()); > System.exit(1); > } >=20 > /* > * Look up connection factory and destination. > */ > try { > connectionFactory =3D > (ConnectionFactory)jndiContext.lookup("ConnectionFactory"); > //destination =3D > (Destination)jndiContext.lookup(destinationName); > } catch (NamingException e) { > LOG.info("JNDI API lookup failed: " + e); > System.exit(1); > } > try { > connection =3D connectionFactory.createConnection(); > session =3D connection.createSession(false, > Session.AUTO_ACKNOWLEDGE); > destination=3D session.createQueue("example.MyQueue"); > =20 > consumer =3D session.createConsumer(destination); > consumer.setMessageListener(this); > Message message1 =3D consumer.receive(1000); > TextMessage txtMsg =3D (TextMessage)message1; > String msg =3D txtMsg.getText(); > System.out.println("Receiving"+msg); > } catch (JMSException e) { > LOG.info("Exception occurred: " + e); > } finally { > if (connection !=3D null) { > try { > connection.close(); > } catch (JMSException e) { > } > } > } > } >=20 > public void onMessage(Message message1) { > // TODO Auto-generated method stub > try > { > message1 =3D consumer.receive(1000); > TextMessage txtMsg =3D (TextMessage)message1; > String msg =3D txtMsg.getText(); > System.out.println("Receiving"+msg); > }catch (JMSException e) { > } > } >=20 > } >=20 >=20 > Can u please tell me why i am getting this error.If i embedd both = producer > and consumer it works file but in different files i am getting = problems. >=20 --=20 View this message in context: http://www.nabble.com/Exception-occurred%3A-javax.jms.IllegalStateExcepti= on%3 A-Cannot-synchronously-receive-a-message-when-a-MessageListener-is-set-tp= 1862 7640p18627931.html Sent from the ActiveMQ - User mailing list archive at Nabble.com.