7 Replies Latest reply on Feb 18, 2014 4:27 AM by Sumanth M S

    onMessage() does not wait unlike in Jboss 4. Is any configuration missed by me?

    Sumanth M S Newbie

      Hi All,

       

      There is a topic "PlayTopic" in standalone-full.xml and a client which tries to asynchronously listen to messages using onMessage() of javax.jms.MessageListener.

      The onMessage() does not wait ( as it was doing in Jboss 4) and exits with following log:

       

      Feb 17, 2014 3:19:01 PM org.xnio.Xnio <clinit>

      INFO: XNIO Version 3.0.6.GA

      Feb 17, 2014 3:19:01 PM org.xnio.nio.NioXnio <clinit>

      INFO: XNIO NIO Implementation Version 3.0.6.GA

      Feb 17, 2014 3:19:01 PM org.jboss.remoting3.EndpointImpl <clinit>

      INFO: JBoss Remoting version 3.2.8.SP1

      Feb 17, 2014 3:19:02 PM org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1$MessageReceiver handleEnd

      ERROR: Channel end notification received, closing channel Channel ID 8d1db2db (outbound) of Remoting connection 00ba5c7a to null

       

      Topic declaration in standalone-full.xml:

      <jms-destinations>

                              <jms-topic name="PlayTopic">

                                      <entry name="topic/PlayTopic"/>

                                      <entry name="java:jboss/exported/topic/PlayTopic"/>

                              </jms-topic>

        </jms-destinations>

       

      Following are the jndi properties being used by the client:

      properties.put("java.naming.factory.initial","org.jboss.naming.remote.client.InitialContextFactory");

      properties.put("java.naming.provider.url", "remote://localhost:4447");

       

      Please let me know if I am doing something not correct for Jboss 7 here.

       

      Thanks.

        • 1. Re: onMessage() does not wait unlike in Jboss 4. Is any configuration missed by me?
          Andy Taylor Master

          Im not really sure what you mean by 'The onMessage() does not wait", could you provide some clearer info please, also, code snippets etc or anything that may help us to help you?

          • 2. Re: Re: onMessage() does not wait unlike in Jboss 4. Is any configuration missed by me?
            Sumanth M S Newbie

            Thanks Andy for the quick reply. Following is the client code I am trying to develop (Jboss 7.1.3. Only jboss-client.jar is in classpath)

             

            import java.util.Properties;

            import javax.jms.Connection;

            import javax.jms.ConnectionFactory;

            import javax.jms.JMSException;

            import javax.jms.Message;

            import javax.jms.MessageConsumer;

            import javax.jms.MessageListener;

            import javax.jms.Session;

            import javax.jms.TextMessage;

            import javax.jms.Topic;

            import javax.naming.Context;

             

            public class JMSClient implements MessageListener {

                public void example() throws Exception

                {

                    String destinationName = "topic/PlayTopic";

                    Context ic = null;

                    ConnectionFactory cf = null;

                    Connection connection =  null;

                    try {      

                        ic = getInitialContext();

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

                        Topic topic = (Topic)ic.lookup(destinationName);

                        connection = cf.createConnection();

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

                        MessageConsumer subscriber = session.createConsumer(topic);

                        subscriber.setMessageListener(this);

                        connection.start();

                    }

                    finally

                    {  if(ic != null){

                            try{

                                ic.close();

                            }

                            catch(Exception e)  {

                                throw e;

                            }

                        }

                        closeConnection(connection);

                    }

                }

                public synchronized void onMessage(Message message)

                {

                    TextMessage text = (TextMessage)message;

                    String strMessage = null;

                    try {

                        strMessage = text.getText();

                    } catch (JMSException e) {

                        e.printStackTrace();

                    }

                    System.out.println("Message received: "+strMessage);

                }

             

             

                private void closeConnection(Connection con) {    

                    try {

                        if (con != null) {

                            con.close();

                        }      

                    }

                    catch(JMSException jmse)   {

                        System.out.println("Could not close connection " + con +" exception was " + jmse);

                    }

                }

             

             

                public static void main(String[] args) throws Exception {

                    new JMSClient().example();

                }

                public static Context getInitialContext( ) throws javax.naming.NamingException {

                    Properties p = new Properties( );

                    p.put("java.naming.factory.initial","org.jboss.naming.remote.client.InitialContextFactory");

                    p.put("java.naming.provider.url", "remote://localhost:4447");

                    return new javax.naming.InitialContext(p);

                }

            }

             

            Since the MessageListener is set to this very object, the onMessage() waits asynchronously for topic messages in Jboss 4. However, that is not the case in jboss 7.

            • 3. Re: Re: onMessage() does not wait unlike in Jboss 4. Is any configuration missed by me?
              Andy Taylor Master

              Since the MessageListener is set to this very object, the onMessage() waits asynchronously for topic messages in Jboss 4. However, that is not the case in jboss 7.

              you need to clarify what you mean by 'waits asynchronously', that doesnt really make much sense, onMessage is called asynchronously by HornetQ there is no waiting any where?

              • 4. Re: onMessage() does not wait unlike in Jboss 4. Is any configuration missed by me?
                Sumanth M S Newbie

                You are right. I am not able to make onMessage() wiat for oncoming messages.

                Jboss 7 appserver is started and the topic gets created and while the appserver is up and running JMSClient is started to listen to any message published onto the said topic. However, what happens is that JMSClient starts and completes the execution immediately ( say, within 1 or 2 seconds) with a log printed on the console:

                 

                INFO: JBoss Remoting version 3.2.8.SP1

                Feb 17, 2014 3:19:02 PM org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1$MessageReceiver handleEnd

                ERROR: Channel end notification received, closing channel Channel ID 8d1db2db (outbound) of Remoting connection 00ba5c7a to null

                 

                Due of this, I am not able to listen to any messages published thereafter onto the topic. Is this expected? Is there any configuration that needs to be done in order to get the above program to continue listen for oncoming messages on the topic.

                • 5. Re: onMessage() does not wait unlike in Jboss 4. Is any configuration missed by me?
                  Andy Taylor Master

                  to be honest, i still dont understand your issue, why would the onMessage method wait, its asynchronous.

                   

                  i would start by looking at the many examples that ship, maybe one of those can help you?

                  • 6. Re: Re: Re: onMessage() does not wait unlike in Jboss 4. Is any configuration missed by me?
                    Miroslav Novak Master

                    I can see the problem. Method example() exits before any message is received. This is because you call connection.start(); and then exits the program. You would have to add Thread.sleep(...) or some check that last message was received.

                    You can also use classic synchronous receive like:

                    while ((message = subscriber.receive(...)) != null) {
                        // do something with message
                    }
                    

                    in example() method.

                     

                    I don't know how this code behaved in JBoss 4 but as it behaves now is expected behavior.

                    1 of 1 people found this helpful