ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ Java / JMS » Publishing to a topic using java classes

Post new topic  Reply to topic
 Publishing to a topic using java classes « View previous topic :: View next topic » 
Author Message
shellj
PostPosted: Fri Nov 11, 2011 7:06 am    Post subject: Publishing to a topic using java classes Reply with quote

Newbie

Joined: 07 Nov 2011
Posts: 5

Hello, I am having trouble getting a publish/subscribe workflow to work properly.

Using MQ Explorer I created a queue called sub_test. I then created a topic with topic name test1, and topic string test2. I then created a subscription linking that topic with that queue.

When I do "test publication" on my topic the message I input gets sent to sub_test queue just fine, so I know my subscription works properly.

My problem, however, is that I cannot seem to publish to my topic from a java application. I get no exceptions or errors, but the message never ends up in the sub_test queue.

Can someone point out what I am doing wrong? Here is the java program I wrote to test this:

Code:

import com.ibm.mq.MQException;
import com.ibm.mq.MQGetMessageOptions;
import com.ibm.mq.MQMessage;
import com.ibm.mq.MQPutMessageOptions;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQQueueManager;
import com.ibm.mq.constants.MQConstants;
import com.ibm.mq.MQEnvironment;
import com.ibm.mq.MQTopic;
import com.ibm.mq.constants.CMQC;

public class MQSubWriter
{
   private static final String param_queue_manager = "my_queue_manager";
   private static final String param_queue_name = "sub_test";
   private static final String param_host_name = "my_qm_server";
   private static final String param_channel_name = "my_qm_channel";

   public static void main(String args[])
   {
      try
      {
         MQEnvironment.hostname = param_host_name;
         MQEnvironment.channel = param_channel_name;
         
         MQQueueManager queue_manager = new MQQueueManager(param_queue_manager);
         
         MQTopic publisher = queue_manager.accessTopic("test2", "test1", CMQC.MQTOPIC_OPEN_AS_PUBLICATION, CMQC.MQOO_OUTPUT);
         
         MQMessage message = new MQMessage();
         
         String message_text = "Sample publisher message";
         
         message.writeString(message_text);
         
         MQPutMessageOptions put_message_options = new MQPutMessageOptions();
         
         publisher.put(message, put_message_options);
         
         publisher.close();
         
         queue_manager.disconnect();
      }
      catch (MQException ex)
      {
         System.out.println("A WebSphere MQ Error occured : Completion Code " + ex.completionCode + " Reason Code " + ex.reasonCode);
         ex.printStackTrace();
         
         for (Throwable t = ex.getCause(); t != null; t = t.getCause())
         {
            System.out.println("... Caused by ");
            t.printStackTrace();
         }
      
      }
      catch (java.io.IOException ex)
      {
         System.out.println("An IOException occured whilst writing to the message buffer: " + ex);
      }
   }
}



I thought I might be sending the parameters in the wrong order in the accessTopic method, so I swapped test1 and test2 but this just threw an exception saying that the topic didn't exist. This leads me to believe that I am publishing to the correct topic, but it doesn't seem to work.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Fri Nov 11, 2011 7:25 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

could it be that you're having issues with 'topic1' versus 'TOPIC1'?
Back to top
View user's profile Send private message
shellj
PostPosted: Fri Nov 11, 2011 7:30 am    Post subject: Reply with quote

Newbie

Joined: 07 Nov 2011
Posts: 5

My actual names are in all caps, and so is the code. I replaced them with generic terms when posting here since this is for a work project and I don't think they would appreciate me divulging anything.
Back to top
View user's profile Send private message
shellj
PostPosted: Fri Nov 11, 2011 8:07 am    Post subject: Reply with quote

Newbie

Joined: 07 Nov 2011
Posts: 5

I solved my problem. It turns out I was misunderstanding what a topic string meant, since the IBM documentation seems to like not being very clear. It turns out topic string isn't supposed to be used at all when publishing to a topic, only the topic name is used.

Accessing the topic like so fixed my problem:

MQTopic publisher = queue_manager.accessTopic("", "topic1", CMQC.MQTOPIC_OPEN_AS_PUBLICATION, CMQC.MQOO_OUTPUT);
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » Publishing to a topic using java classes
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.