MQ

 View Only
Expand all | Collapse all

Unable to create dynamic queue in IBMMQ using this: session.createQueue("myqueue");

  • 1.  Unable to create dynamic queue in IBMMQ using this: session.createQueue("myqueue");

    Posted 18 days ago
    Hi,
    IBM MQ community: 
    I'm trying to create and open a queue that doesn't exist yet in IBM MQ, but I get the error "Failed to open MQ queue 'myqueue'". 
     
    As IBM MQ isn't allowing to create queues dynamically like some other systems (such as ActiveMQ), in which session.createQueue("myqueue") creates a new queue. 
    POC:
    import com.ibm.mq.jakarta.jms.MQConnectionFactory;
    import com.ibm.msg.client.jakarta.wmq.WMQConstants;
    import jakarta.jms.*;
    
    public class Main {
      public static void main(String[] args) {
        try {
          // Set up MQ connection factory
          MQConnectionFactory factory = new MQConnectionFactory();
          factory.setHostName("myip");
          factory.setPort(1414);
          factory.setQueueManager("QM1");
          factory.setChannel("DEV.APP.SVRCONN");
          factory.setTransportType(WMQConstants.WMQ_CM_CLIENT);
    
          JMSContext context = factory.createContext("app", "passw0rd");
          Queue dynamicQueue = context.createQueue("myqueue");  // Target queue
    
          // Send a message
          BytesMessage msg = context.createBytesMessage();
          msg.writeBytes("Hello, IBM MQ!".getBytes());
          msg.setJMSReplyTo(dynamicQueue);
          context.createProducer().send(dynamicQueue, msg);
    
          System.out.println("Message sent to dynamic queue.");
        } catch (JMSException e) {
          e.printStackTrace();
        }
      }
    }
    

    Error stacktrace:

    "C:\Program Files\OpenJDK\jdk-8.0.362.09-hotspot\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.3.1\lib\idea_rt.jar=53253:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.3.1\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\OpenJDK\jdk-8.0.362.09-hotspot\jre\lib\charsets.jar;C:\Program Files\OpenJDK\jdk-8.0.362.09-hotspot\jre\lib\ext\access-bridge-64.jar;C:\Program Files\OpenJDK\jdk-8.0.362.09-hotspot\jre\lib\ext\cldrdata.jar;C:\Program Files\OpenJDK\jdk-8.0.362.09-hotspot\jre\lib\ext\dnsns.jar;C:\Program Files\OpenJDK\jdk-8.0.362.09-hotspot\jre\lib\ext\jaccess.jar;C:\Program Files\OpenJDK\jdk-8.0.362.09-hotspot\jre\lib\ext\jfxrt.jar;C:\Program Files\OpenJDK\jdk-8.0.362.09-hotspot\jre\lib\ext\localedata.jar;C:\Program Files\OpenJDK\jdk-8.0.362.09-hotspot\jre\lib\ext\nashorn.jar;C:\Program Files\OpenJDK\jdk-8.0.362.09-hotspot\jre\lib\ext\sunec.jar;C:\Program Files\OpenJDK\jdk-8.0.362.09-hotspot\jre\lib\ext\sunjce_provider.jar;C:\Program Files\OpenJDK\jdk-8.0.362.09-hotspot\jre\lib\ext\sunmscapi.jar;C:\Program Files\OpenJDK\jdk-8.0.362.09-hotspot\jre\lib\ext\sunpkcs11.jar;C:\Program Files\OpenJDK\jdk-8.0.362.09-hotspot\jre\lib\ext\zipfs.jar;C:\Program Files\OpenJDK\jdk-8.0.362.09-hotspot\jre\lib\jce.jar;C:\Program Files\OpenJDK\jdk-8.0.362.09-hotspot\jre\lib\jfr.jar;C:\Program Files\OpenJDK\jdk-8.0.362.09-hotspot\jre\lib\jfxswt.jar;C:\Program Files\OpenJDK\jdk-8.0.362.09-hotspot\jre\lib\jsse.jar;C:\Program Files\OpenJDK\jdk-8.0.362.09-hotspot\jre\lib\management-agent.jar;C:\Program Files\OpenJDK\jdk-8.0.362.09-hotspot\jre\lib\resources.jar;C:\Program Files\OpenJDK\jdk-8.0.362.09-hotspot\jre\lib\rt.jar;D:\github-platform\platform\code\java\JMSDynamicQueue\out\production\JMSDynamicQueue;C:\Program Files\IBM\MQ\java\lib\jakarta.jms-api.jar;C:\Program Files\IBM\MQ\java\lib\com.ibm.mq.jakarta.client.jar" Main
    Exception in thread "main" com.ibm.msg.client.jakarta.jms.DetailedInvalidDestinationRuntimeException: JMSWMQ2007: Failed to send a message to destination 'myqueue'.
    JMS attempted to perform an MQPUT or MQPUT1; however IBM MQ reported an error.
    Use the linked exception to determine the cause of this error.
    	at com.ibm.msg.client.jakarta.jms.DetailedInvalidDestinationException.getUnchecked(DetailedInvalidDestinationException.java:274)
    	at com.ibm.msg.client.jakarta.jms.internal.JmsErrorUtils.convertJMSException(JmsErrorUtils.java:173)
    	at com.ibm.msg.client.jakarta.jms.internal.JmsProducerImpl.send(JmsProducerImpl.java:618)
    	at Main.main(Main.java:23)
    Caused by: com.ibm.mq.MQException: JMSCMQ0001: IBM MQ call failed with compcode '2' ('MQCC_FAILED') reason '2085' ('MQRC_UNKNOWN_OBJECT_NAME').
    	at com.ibm.msg.client.jakarta.wmq.common.internal.Reason.createException(Reason.java:203)
    	at com.ibm.msg.client.jakarta.wmq.internal.WMQMessageProducer.checkJmqiCallSuccess(WMQMessageProducer.java:1358)
    	at com.ibm.msg.client.jakarta.wmq.internal.WMQMessageProducer.checkJmqiCallSuccess(WMQMessageProducer.java:1313)
    	at com.ibm.msg.client.jakarta.wmq.internal.WMQMessageProducer.access$800(WMQMessageProducer.java:75)
    	at com.ibm.msg.client.jakarta.wmq.internal.WMQMessageProducer$SpiUnidentifiedProducerShadow.sendInternal(WMQMessageProducer.java:1123)
    	at com.ibm.msg.client.jakarta.wmq.internal.WMQMessageProducer$ProducerShadow.send(WMQMessageProducer.java:608)
    	at com.ibm.msg.client.jakarta.wmq.internal.WMQMessageProducer.send(WMQMessageProducer.java:1487)
    	at com.ibm.msg.client.jakarta.jms.internal.JmsMessageProducerImpl.sendMessage(JmsMessageProducerImpl.java:855)
    	at com.ibm.msg.client.jakarta.jms.internal.JmsMessageProducerImpl.synchronousSendInternal(JmsMessageProducerImpl.java:2055)
    	at com.ibm.msg.client.jakarta.jms.internal.JmsMessageProducerImpl.sendInternal(JmsMessageProducerImpl.java:1993)
    	at com.ibm.msg.client.jakarta.jms.internal.JmsMessageProducerImpl.send(JmsMessageProducerImpl.java:1535)
    	at com.ibm.msg.client.jakarta.jms.internal.JmsProducerImpl.send(JmsProducerImpl.java:609)
    	... 1 more
    
    Process finished with exit code 1
    

    Is there a solution or alternative approach to achieve this in IBM MQ?

    #IBMMQ#IBMMQ



    ------------------------------
    gourav kumar
    ------------------------------


  • 2.  RE: Unable to create dynamic queue in IBMMQ using this: session.createQueue("myqueue");

    Posted 17 days ago

    Hi Gourav,
    in IBM MQ you need a model queue to create a dynamic queue.
    And since your API is JMS, as far as I know (and after quick browsing of the doc) the only way to use this feature is to use a TemporaryQueue.

    TemporaryQueue q3 = session.createTemporaryQueue();
    TEMPMODEL property of the connection factory specifies the model queue used (it must exist and you must have persmission to use it)
    TEMPQPREFIX property of the connection factory specifies the naming prefix of the temporary dynamic queue wich will be created. So you don't decide the full name of the dynamic queue, only the prefix.

    If the model queue has the DEFTYPE property set to TEMPDYN then the TemporaryQueue is destroyed with the JMS session
    If DEFTYPE is set to PERMDYN the TemporaryQueue is not automatically destroyed, your code is supposed to call .delete() on the TemporaryQueue object to delete it.
    This is defined by the MQ administrator.

    If the queue is to remain permanently you should not use the dynamic feature but ask your MQ administrator to create a queue. Anyway you see that even with dynamic queue you need a model queue. There are model queues created by default in IBM MQ (at least the one wich is specified by default in a connection factory), but even if you use an existing model queue you will probably need your mq administrator to give you the necessary authorizations to use it.

    see also
    https://www.ibm.com/docs/en/ibm-mq/9.3?topic=applications-creating-destinations-in-jms-application
    https://www.ibm.com/docs/en/ibm-mq/9.3?topic=wmcjma-accessing-mq-features-from-mq-classes-jms-application
    https://www.ibm.com/docs/api/v1/content/SSFKSJ_9.3.0/javadoc/WMQJMS30Classes/com/ibm/mq/jakarta/jms/MQTemporaryQueue.html#delete--



    ------------------------------
    YVES MOYROUD
    ------------------------------