4 Replies Latest reply: Jul 28, 2011 10:38 AM by murgir_jhol RSS

    Query regarding publishing to a topic in Sun MQ 4.4

    murgir_jhol
      Hi,
      I am absolutely new to Sun MQ.Last day I was trying to publish to a topic using the follwing java code:-


      ConnectionFactory myFctry=new ConnectionFactory();
      myFctry.setProperty(ConnectionConfiguration.imqAddressList, "localhost:7676");
      myFctry.setProperty(ConnectionConfiguration.imqReconnectEnabled,"true");
      Connection myConnection=myFctry.createConnection();
      javax.jms.Session mySession= myConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Destination myDest=mySession.createTopic("myTestTopic");
      MessageProducer myProducer=mySession.createProducer(myDest);
      System.out.println(myProducer.getDestination());
      TextMessage outMsg=mySession.createTextMessage();
      outMsg.setText("yahoooo again!!!!");
      myProducer.send(outMsg);
      mySession.close();
      myConnection.close();
      System.out.println("message published");


      Although this piece of code is working for a queue(I just replaced the destination with Destination myDest=mySession.createQueue("myTestTopic")).But the above code is not working for a topic.I've been stuck here fro long.Please help.

      Thanks in advance
        • 1. Re: Query regarding publishing to a topic in Sun MQ 4.4
          nigeldeakin
          I am absolutely new to Sun MQ
          With that in mind, I must ask the following question: Are you using a durable or a non-durable subscription to consume messages from the topic? If you're using Session.createConsumer or TopicSession.createSubscriber() then you're using a non-durable subscription, and this must be set up BEFORE you send the message to the topic, or else the message will be thrown away.

          Nigel
          • 2. Re: Query regarding publishing to a topic in Sun MQ 4.4
            murgir_jhol
            Thanks a ton for your reply.I am using non durable subscription.It might sound like a stupid question but do I have to set up a consumer before sending any messages to a topic?Where can I find documentation or any information about this.I was following the developer's guide for Sun MQ 4.4.Thanks again for your reply.
            • 3. Re: Query regarding publishing to a topic in Sun MQ 4.4
              nigeldeakin
              Thanks a ton for your reply.I am using non durable subscription.It might sound like a stupid question but do I have to set up a consumer before sending any messages to a topic?
              Yes, that is correct. This is explained in any textbook on JMS. It's also explained in the JMS tutorial
              http://download.oracle.com/javaee/1.3/jms/tutorial/1_3_1-fcs/doc/basics.html#1023551
              Where can I find documentation or any information about this.I was following the developer's guide for Sun MQ 4.4.Thanks again for your reply.
              It's mentioned in this section of that document:
              http://download.oracle.com/docs/cd/E19587-01/821-0029/aeqay/index.html

              "If no active consumers are registered for a topic, the topic does not hold the messages it receives unless it has inactive consumers with durable subscriptions."

              Nigel