You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用com.ibm.mq.allclient连接本地IBM MQ容器遇Completion Code 2、Reason 2035错误

IBM MQ 连接报错Completion Code '2'、Reason '2035' 问题解决

问题描述

使用Spring Boot服务连接本地IBM MQ容器,客户端代码如下:

package com.tsdevelopment.spring_boot_ibmmq_producer;

import com.ibm.mq.MQException;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQQueueManager;
import com.ibm.mq.constants.CMQC;
import org.springframework.stereotype.Service;
import java.io.IOException;

@Service
public class IBMMQProducer {

    public void sendMessage(RequestPayload requestPayload) throws MQException, IOException {
        MQQueueManager queueManager = null;

        try {
            // Set up MQ environment
            com.ibm.mq.MQEnvironment.hostname = "localhost";
            com.ibm.mq.MQEnvironment.port = 1414;
            com.ibm.mq.MQEnvironment.channel = "TSCHANNEL";
            com.ibm.mq.MQEnvironment.userID = "mqm";
            com.ibm.mq.MQEnvironment.password = "pass";

            // Create a connection to the queue manager
            queueManager = new MQQueueManager("TS_IBMMQ_MANAGER");

            // Specify the queue that you want to open
            int openOptions = CMQC.MQOO_OUTPUT;
            MQQueue queue = queueManager.accessQueue("TS_QUEUE", openOptions);

            // Create a message
            com.ibm.mq.MQMessage mqMessage = new com.ibm.mq.MQMessage();
            mqMessage.writeString(requestPayload.getRequestField());

            // Specify the message options
            com.ibm.mq.MQPutMessageOptions pmo = new com.ibm.mq.MQPutMessageOptions();

            // Put the message on the queue
            queue.put(mqMessage, pmo);

            // Close the queue
            queue.close();

        } finally {
            // Disconnect from the queue manager
            if (queueManager != null) {
                queueManager.disconnect();
            }
        }
    }
}

已在MQ容器中执行以下命令创建通道和队列:

echo "DEFINE CHANNEL(TSCHANNEL) CHLTYPE(SVRCONN) TRPTYPE(TCP) REPLACE" | runmqsc TS_IBMMQ_MANAGER
echo "DEFINE QLOCAL(TS_QUEUE)" | runmqsc TS_IBMMQ_MANAGER

连接时出现Completion Code '2'、Reason '2035'错误。

问题定位

这是MQ配置问题,客户端代码本身没有错误。Reason 2035代表权限验证失败,具体原因:

  • 创建的SVRCONN通道默认未授权用户mqm通过该通道连接队列管理器
  • 即使是管理员用户mqm,也需要明确配置权限才能访问队列管理器和目标队列

解决步骤

  1. 进入MQ容器:
docker exec -it <你的MQ容器ID/名称> bash
  1. 进入队列管理器配置环境:
runmqsc TS_IBMMQ_MANAGER
  1. 授权用户mqm连接队列管理器:
SET AUTHREC PROFILE('self') OBJTYPE(QMGR) PRINCIPAL('mqm') AUTHADD(CONNECT,INQ)
  1. 授权用户mqm对目标队列执行写入操作:
SET AUTHREC PROFILE('TS_QUEUE') OBJTYPE(QUEUE) PRINCIPAL('mqm') AUTHADD(PUT,INQ)
  1. (测试环境可选)临时关闭通道身份验证(生产环境禁用此操作):
ALTER CHANNEL(TSCHANNEL) CHLTYPE(SVRCONN) MCAUSER('mqm')
  1. 退出配置环境:
END

完成以上配置后,重新运行客户端代码即可正常连接并发送消息。

内容的提问来源于stack exchange,提问作者TSSK

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 03:37:05