1 Reply Latest reply on Feb 6, 2014 7:28 AM by Miroslav Novak

    JMS provider does not deliver messages to MessageListener

    Saleh Noures Newbie

      Hi folks,

       

       

      I’m new to both JMS and JBoss, actually I’m trying to create JMS remote clients to send and receive messages through JMS provider (JBoss 7.1), sending messages is working fine but i have problem with receiving messages using MessageListener.

      when I lunch the consumer the consumer counter get increased in JBoss admin console and when I send messages to the queue, the messages in queue counter get increased as well but nothing happens. meaning the MessageListener doesn’t get called to consume the message.

      The code is here:

      ////////////////////////////////Message producer////////////////////////////////

      public class JmsProd {

             public static void main(String[] args) throws NamingException,JMSException {  
              Context context= getInitialContext();

              ConnectionFactory cf =(ConnectionFactory) context.lookup("jms/RemoteConnectionFactory");

              Queue queue = (Queue) context.lookup("jms/queue/test");

              Connection connection=cf.createConnection();

              Session session=connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

                      MessageProducer prod=session.createProducer(queue);

              TextMessage m=session.createTextMessage("Hi From Saleh(7)");

              prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

              prod.send(m);

              System.out.println("***************TXT MSG HAS BEEN SENT***************");

              context.close();

              connection.close();

             }

       

             public static ContextgetInitialContext() throws NamingException

             {…}

       

      /////////////////////////Message consumer///////////////////////////

       

      public class JmslistenerCons  {

      public static void main(String[] args) throws NamingException,JMSException {

             Context context= getInitialContext();

                    ConnectionFactory cf =(ConnectionFactory) context.lookup("jms/RemoteConnectionFactory");   
             Queue queue = (Queue) context.lookup(
      "jms/queue/test");

             Connection connection =cf.createConnection();
             Session session=connection.createSession(
      false, Session.AUTO_ACKNOWLEDGE);

             MessageConsumerconsum=session.createConsumer(queue);   
             consum.setMessageListener(
      new MsgListener());   

             connection.start();

              System.out.print("***************MSG must be consumed by MSG listener***************");

             }

             public static ContextgetInitialContext() throws NamingException

             {…}

       

      //////////////////////message listener/////////////////////////////

       

       

      public class MsgListener implements MessageListener {

             @Override

             public void onMessage(Messagemsg) {

                    try {

                    System.out.println(((TextMessage)msg).getText());

                    } catch (JMSException e) {

                                 e.printStackTrace();

                           }

             }

       

      }