java(Spring Boot)中的MQ异常MQRC_UNKNOWN_OBJECT_NAME后需要继续

need to continue after the MQ exception MQRC_UNKNOWN_OBJECT_NAME in java( Sprinngboot)

我有以下方法向 MQ 发送消息,当队列名称不正确时会抛出 MQRC_UNKNOWN_OBJECT_NAME 错误,但我想传递自定义错误(类似于“找不到队列名称”)并让用户继续使用正确的队列名称。我试图通过将 mqSend() 方法返回为 false 来捕获消息发送不成功的情况。但它没有像我预期的那样工作。有人可以帮我吗? (请注意,我正在分别设置所需的 MQ 属性(QUEUE_NAME、QMGR、CHANNEL、HOST、PORT)。

    public boolean mqSend()
    {
        

        

    
        String APP_USER = ""; // User name that application uses to connect to MQ
        String APP_PASSWORD = ""; // Password that the application uses to connect to MQ

        
        // Variables
        JMSContext context = null;
        Destination destination = null;
        JMSProducer producer = null;
        //JMSConsumer consumer = null;
        
        
        try {
            // Create a connection factory
            JmsFactoryFactory ff = JmsFactoryFactory.getInstance(WMQConstants.WMQ_PROVIDER);
            JmsConnectionFactory cf = ff.createConnectionFactory();

            // Set the properties
            cf.setStringProperty(WMQConstants.WMQ_HOST_NAME, HOST);
            cf.setIntProperty(WMQConstants.WMQ_PORT, PORT);
            cf.setStringProperty(WMQConstants.WMQ_CHANNEL, CHANNEL);
            cf.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_CLIENT);
            cf.setStringProperty(WMQConstants.WMQ_QUEUE_MANAGER, QMGR);
            cf.setStringProperty(WMQConstants.WMQ_APPLICATIONNAME, "Manual message publihser");
            cf.setBooleanProperty(WMQConstants.USER_AUTHENTICATION_MQCSP, true);
            cf.setStringProperty(WMQConstants.USERID, APP_USER);
            cf.setStringProperty(WMQConstants.PASSWORD, APP_PASSWORD);
            
            //cf.setStringProperty(WMQConstants.WMQ_SSL_CIPHER_SUITE, "*TLS12");

            // Create JMS objects
            context = cf.createContext();
            
            destination = context.createQueue("queue:///" + QUEUE_NAME);
            ((MQDestination)destination).setTargetClient(JMSC.MQJMS_CLIENT_NONJMS_MQ);
            

            //long uniqueNumber = System.currentTimeMillis() % 1000;
            //TextMessage message = context.createTextMessage("Your lucky number today is " + uniqueNumber);
            TextMessage message = context.createTextMessage(MESSAGE);
            
            
            producer = context.createProducer();
            producer.send(destination, message);
            System.out.println("<INFO> : Sent message details:\n" + message);

            //consumer = context.createConsumer(destination); // autoclosable
            //String receivedMessage = consumer.receiveBody(String.class, 15000); // in ms or 15 seconds

            //System.out.println("\nReceived message:\n" + receivedMessage);

                        context.close();
return true;
            //recordSuccess();
        } catch (JMSException jmsex) {
            //recordFailure(jmsex);
            System.out.println("JMS/MQ error OCCURED!!!!");
return false;
        }
        

        //System.exit(status);
        
        
    }

producer.send 调用包装在自己的 try/catch 中并查找 MQRC_UNKNOWN_OBJECT_NAME 或其他错误,例如 MQRC_NOT_AUTHORIZEDMQRC_Q_FULL.