Create topic in IBM MQ in java program

I want to create a topic named "manipulation" in my Java application, but I am getting this error:

Exception in thread "main" com.ibm.mq.MQException: MQJE001: Completion Code '2', Reason '2085'

      

My code:

MQTopic subscriber = new MQTopic(queueManager, null, "manipulation",CMQC.MQTOPIC_OPEN_AS_SUBSCRIPTION, CMQC.MQSO_CREATE);

      

as said here:

Accessing Queues, Threads, and Processes in IBM MQ for Java Classes

+3


source to share


2 answers


The code you are using to create a theme subscription needs a little modification to get it working:

MQTopic subscriber = new MQTopic(queueManager, null, "manipulation",CMQC.MQTOPIC_OPEN_AS_SUBSCRIPTION, CMQC.MQSO_CREATE);

      

In the snippet above, you have specified the third parameter, for example the object name. When you specify the name of a theme object, that object must exist before using it. In your case, you are administratively creating a named theme object manipulation

and then use the constructor above to create the subscription. Since the topic manipulation

does not exist, an exception is thrown MQRC 2085

.

You have two options:



1) Administratively create a "manipulation" theme object.

2) If you don't want to create a theme object, then create a subscription on the fly without using the theme object name as shown below.

MQTopic subscriber = queueManager.accessTopic("manipulation", "", CMQC.MQTOPIC_OPEN_AS_SUBSCRIPTION, CMQC.MQSO_MANAGED | CMQC.MQSO_CREATE | CMQC.MQOO_FAIL_IF_QUIESCING);

      

+4


source


MQ Exception 2085 means MQRC_UNKNOWN_OBJECT_NAME

Invalid object name in the queue.

Sample code:

try {       
     MQTopicConnectionFactory cf = new MQTopicConnectionFactory();        
     // Config       
     cf.setHostName("<Destination-IP>");       
     cf.setPort(1414);
     cf.setTransportType(JMSC.MQJMS_TP_CLIENT_MQ_TCPIP);           
     cf.setQueueManager("<Queue-Manager-Name>");          
     cf.setChannel("SYSTEM.DEF.SVRCONN");        
     MQTopicConnection connection = (MQTopicConnection) cf.createTopicConnection();       
     MQTopicSession session = (MQTopicSession) connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);       
     MQTopic topic = (MQTopic) session.createTopic("topic://test");              
     MQTopicPublisher publisher =  (MQTopicPublisher) session.createPublisher(topic);       
     MQTopicSubscriber subscriber = (MQTopicSubscriber) session.createSubscriber(topic);              
     JMSTextMessage message = (JMSTextMessage) session.createTextMessage("Hello World");             
     // Start the connection      
     connection.start();        
     publisher.publish(message);       
     log.info("Sent message:" + message);        
     JMSMessage receivedMessage = (JMSMessage) subscriber.receive(10000);        
     log.info("Received message:" + receivedMessage);        
     publisher.close();       
     subscriber.close();       
     session.close();       
     connection.close();        
     log.info("SUCCESS");     
     } catch (JMSException jex) {       
       log.error(jex.getMessage());            
     } catch (Exception ex) {       
       log.error(ex.getMessage());       
      System.out.println("\\nFAILURE\\n");     
  }   
}

      



You can also do the same from the command line

crtmqm QM_A //Create Queue-Manager
strmqm QM_A //Start Queue-Manager
runmqsc QM_A //Open Websphere MQ CLI
DEFINE LISTENER(A.LISTENER) TRPTYPE(TCP) CONTROL(QMGR) PORT(1414) //Define Listener
START LISTENER(A.LISTENER) //Start Listener
DEFINE CHANNEL(A.CHANNEL) CHLTYPE(SVRCONN) //Define Channel
START CHANNEL(A.CHANNEL) // Start Channel
DEFINE QLOCAL(A.QUEUE) MAXDEPTH(50000) //Define LocalQueue
DEFINE TOPIC(A.TOPIC) TOPICSTR('A') //Define Topic
DEFINE SUB(A.SUBQUEUE) DEST(A.QUEUE) TOPICOBJ(A.TOPIC) REPLACE; //Link Subscription Queue with Topic

      

Visit http://bencane.com/2013/04/22/websphere-mq-cheat-sheet-for-system-administrators/

+1


source







All Articles