0 Replies Latest reply on Oct 24, 2012 10:06 AM by Florin Slev

    Inconsistent hornetQ wildCard results:

    Florin Slev Newbie

      Hello,

       

      I made an example of hornetq wildcards exercise. The problem is that when I run this code, the first time, everything is ok. But, the second time an error appears:

       

      "java.lang.NullPointerException

          at org.hornetq.simple.client.examples.routing.HornetQWildCardExample.main(HornetQWildCardExample.java:100)"

       

      Line 100:   System.out.println("HornetQ Core Client WorldNewsConsumer received message = "

                          + msgReceived.getBodyBuffer().readString());

       

      This is the source code:

       

      ServerLocator locator = HornetQClient.createServerLocatorWithoutHA(transportConfiguration);

       

              ClientSessionFactory factory = null;

              ClientSession session = null;

       

              final String topicEuroNewsSubscribe = "TopicEuroNewsSubscribe";

              final String topicWorldNewsSubscribe = "TopicWorldNewsSubscribe";

              ClientConsumer euroNewsConsumer = null;

              ClientConsumer worldNewsConsumer = null;

       

              final String addressEuroNewsWildCard = "jms.topic.news.europe.#";

              final String addressWorldNewsWildCard = "jms.topic.news.#";

       

              final String addressNewsEurope = "jms.topic.news.europe";

              final String addressNewsEuropeBoxing = "jms.topic.news.europe.boxing";

              final String addressNewsUsa = "jms.topic.news.usa";

       

              try {

       

                  factory = locator.createSessionFactory();

                  session = factory.createSession(APPLICATIONREALM_USER, APPLICATIONREALM_USER_PWD,

                          false, true, true, false, 5);

       

                  session.createQueue(addressEuroNewsWildCard, topicEuroNewsSubscribe, true);

                  session.createQueue(addressWorldNewsWildCard, topicWorldNewsSubscribe, true);

       

                  // Anonymous producer

                  ClientProducer producer = session.createProducer();

                  euroNewsConsumer = session.createConsumer(topicEuroNewsSubscribe);

                  worldNewsConsumer = session.createConsumer(topicWorldNewsSubscribe);

       

                  ClientMessage euroNewsmessage = session.createMessage(true);

                  euroNewsmessage.getBodyBuffer().writeString("EuroNews No Comment.");

       

                  ClientMessage euroNewsBoxingMessage = session.createMessage(true);

                  euroNewsBoxingMessage.getBodyBuffer().writeString("Bute TKO in Londra.");

       

                  ClientMessage usaNewsMessage = session.createMessage(true);

                  usaNewsMessage.getBodyBuffer().writeString("USA news.");

       

                  session.start();

       

                  producer.send(addressNewsEurope, euroNewsmessage);

                  producer.send(addressNewsEuropeBoxing, euroNewsBoxingMessage);

                  producer.send(addressNewsUsa, usaNewsMessage);

       

                  ClientMessage msgReceived = euroNewsConsumer.receive(5000);

                  System.out.println("HornetQ Core Client EuroNewsConsumer received message = "

                          + msgReceived.getBodyBuffer().readString());

                  msgReceived = euroNewsConsumer.receive(5000);

                  System.out.println("HornetQ Core Client EuroNewsConsumer received message = "

                          + msgReceived.getBodyBuffer().readString());

       

                  msgReceived = worldNewsConsumer.receive(5000);

                  System.out.println("HornetQ Core Client WorldNewsConsumer received message = "

                          + msgReceived.getBodyBuffer().readString());

                  msgReceived = worldNewsConsumer.receive(5000);  // LINE 100 <--- An exception is thrown here when this example is ran the second time

                  System.out.println("HornetQ Core Client WorldNewsConsumer received message = "

                          + msgReceived.getBodyBuffer().readString());

                  msgReceived = worldNewsConsumer.receive(5000);

                  System.out.println("HornetQ Core Client WorldNewsConsumer received message = "

                          + msgReceived.getBodyBuffer().readString());

       

                  if (worldNewsConsumer.receive(5000) != null) {

                      Assert.fail("WorldNewsConsumer must not receive any more messages");

                  }

                  if (euroNewsConsumer.receive(5000) != null) {

                      Assert.fail("EuroNewsConsumer must not receive any more messages");

                  }

       

              } catch (Exception e) {

                  e.printStackTrace();

              } finally {

       

                  if (euroNewsConsumer != null) {

                      try {

                          euroNewsConsumer.close();

                          euroNewsConsumer = null;

                      } catch (HornetQException e) {

                          e.printStackTrace();

                      }

                  }

       

                  if (worldNewsConsumer != null) {

                      try {

                          worldNewsConsumer.close();

                          worldNewsConsumer = null;

                      } catch (HornetQException e) {

                          e.printStackTrace();

                      }

                  }

       

                  if (session != null)

                      try {

       

                          session.deleteQueue(topicEuroNewsSubscribe);

                          session.deleteQueue(topicWorldNewsSubscribe);

                          session.close();

                      } catch (HornetQException e) {

                          e.printStackTrace();

                      }

              }

          }

       

       

      If I run it the 3rd time, everything works ok.  The 4th time , exception, and so on ....

      I cannot figure where the problem is.