8 Replies Latest reply on Jun 4, 2012 10:33 AM by lauradp

    Topics with AS7 and HornetQ

    lauradp

      Hello everybody!

      I'm trying to develop a simple application with a publisher and a subscriber.

      To publish a message I wrote che following instructions:

       

      Properties env = new Properties();

      env.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);

      env.put(Context.PROVIDER_URL, PROVIDER_URL);

      env.put(Context.SECURITY_PRINCIPAL, DEFAULT_USERNAME);

      env.put(Context.SECURITY_CREDENTIALS, DEFAULT_PASSWORD);

      env.put("jboss.naming.client.ejb.context", true);

      Context ctx = new InitialContext(env);

      tconFactory = (TopicConnectionFactory) PortableRemoteObject.narrow(ctx.lookup("jms/RemoteConnectionFactory"),TopicConnectionFactory.class);

      tcon = tconFactory.createTopicConnection(DEFAULT_USERNAME,DEFAULT_PASSWORD);

      tsession = tcon.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

      topic = (Topic) PortableRemoteObject.narrow(ctx.lookup("jms/"+topicName), Topic.class);

      tpublisher = tsession.createPublisher(topic);

      msg = tsession.createTextMessage();

      tcon.start();

      System.out.println("Topic Sender");

      System.out.println("Following Messages has been sent !!!");

      System.out.println("====================================");

      for(int j=1;j<=3;j++){

                          msg.setText(""+j);                     // Messages

                          tpublisher.publish(msg);           // Messages sent

                System.out.println("Message Sent = "+j);

      }

      System.out.println("====================================");

       

      When I run these instructions I get no error but I cannot see any message from JBoss  Administration Console. Is there any error?

        • 1. Re: Topics with AS7 and HornetQ
          jmesnil

          do you have a subscriber listening on the topic?

           

          If there are no consumer connected (or durable subscribers), HornetQ will discard the messages sent to the topic (since nobody is interested by them).

          • 2. Re: Topics with AS7 and HornetQ
            jbertram

            Your code looks fine as far as I can tell.  Although you should try to use ConnectionFactory, Session, Destination, and MessageProducer rather than TopicConnectionFactory, TopicSession, Topic, and TopicPublisher respectively since that is the recommendation from the JMS spec.

             

            Jeff is right.  This is basic JMS semantics with topics.

             

            Try using a queue rather than a topic.

            1 of 1 people found this helpful
            • 3. Re: Topics with AS7 and HornetQ
              clebert.suconic

              TopicConnection and QueueConnection are obsolete interfaces. try to use the unified ones.

              • 4. Re: Topics with AS7 and HornetQ
                lauradp

                Thanks for your answers!

                I was trying to develop an example about queues and one about topics in HORNETQ.That's why I used topics instead of queues.

                What's is the unified interface??

                 

                Thanks

                Laura

                • 5. Re: Topics with AS7 and HornetQ
                  jbertram

                  Using a topic is fine as long as you understand the basic semantics (i.e. if there are no subscriptions any message sent to the topic will be discarded).

                   

                  The "unified" interfaces are the ones I referred to in my previous comment.  To be clear, these are unified:

                  • ConnectionFactory
                  • Session
                  • Destination
                  • MessageProducer

                   

                  These are not unified:

                  • QueueConnectionFactory, TopicConnectionFactory
                  • QueueSession, TopicSession
                  • Queue, Topic
                  • QueueSender, TopicPublisher
                  1 of 1 people found this helpful
                  • 6. Re: Topics with AS7 and HornetQ
                    lauradp

                    Thank you Justin,

                    so you are suggesting me to always use the unified interfaces and to let "ebj-jar.xml" file to specify the destination type. Isn't it?

                     

                    thanks

                    Laura

                    • 7. Re: Topics with AS7 and HornetQ
                      jbertram

                      I am suggesting that you use the unified interfaces, but I'm not sure where ejb-jar.xml enters your use-case.  You haven't mentioned it until now.  It shouldn't be related at all to how messages are produced.  In terms of messaging, It only controls the behavior of an MDBs consumption of a message.

                      • 8. Re: Topics with AS7 and HornetQ
                        lauradp

                        ok, thanks

                         

                        Laura