Note that there are some explanatory texts on larger screens.

plurals
  1. POwhile runnning jms queue producer sends message and consumer gets message but message is not displayed
    text
    copied!<p>Hi i have java code which has a producer and a consumer. the producer sends the message to a queue and the consumer also gets the message but i do not know why the message is not displayed. I am using activeMQ and as i was not getting the message so i checked in the in the http:/localhost:8161/admin/queues.jsp and there it shows the queue has both producer and consumer But the message is not printed in the command prompt.Please tell me</p> <p>producer.java</p> <pre><code>import javax.jms.*; import org.apache.activemq.ActiveMQConnection; import org.apache.activemq.ActiveMQConnectionFactory; public class Producer { private static String url = ActiveMQConnection.DEFAULT_BROKER_URL; private static String subject = "test"; public static void main(String[] args) throws JMSException { ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url); Connection connection = connectionFactory.createConnection(); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination destination = session.createQueue(subject); MessageProducer producer = session.createProducer(destination); TextMessage message = session.createTextMessage("this is a g message"); producer.send(message); System.out.println("Sent message '" + message.getText() + "'"); System.out.println( ActiveMQConnection.DEFAULT_BROKER_URL); connection.close(); } } </code></pre> <p>consumer.java</p> <pre><code>import javax.jms.*; import org.apache.activemq.ActiveMQConnection; import org.apache.activemq.ActiveMQConnectionFactory; public class Consumer { private static String url = ActiveMQConnection.DEFAULT_BROKER_URL; private static String subject = "test"; public static void main(String[] args) throws JMSException { ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url); Connection connection = connectionFactory.createConnection(); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination destination = session.createQueue(subject); MessageConsumer consumer = session.createConsumer(destination); Message message = consumer.receive(); if (message instanceof TextMessage) { TextMessage textMessage = (TextMessage) message; System.out.println("Received message '" + textMessage.getText() + "'"); } connection.close(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload