解决IBM Code Engine中Node.js应用连接IBM MQ的MQRC_NOT_AUTHORIZED错误
我正在使用IBM Cloud的Code Engine及IBM Code Engine示例项目,在Docker容器中运行的Node.js应用连接远程IBM MQ服务器时遇到授权问题,尽管已配置必要的环境变量和设置,应用仍失败并抛出以下错误:
MQError: OPEN: MQCC = MQCC_FAILED [2] MQRC = MQRC_NOT_AUTHORIZED [2035]
环境与配置
- Node.js版本:18
- 构建阶段Docker基础镜像:ubuntu:20.04
- 运行阶段Docker基础镜像:node:16-slim
- IBM MQ Node.js模块:ibmmq
Dockerfile内容
# Stage 1: Build FROM ubuntu:20.04 as builder ENV NODE_VERSION 18 ENV APP_DIR /usr/local/clientapp WORKDIR ${APP_DIR} RUN apt-get update \ && apt-get install -y --no-install-recommends curl gcc g++ make git ca-certificates \ && curl --silent -k --location https://deb.nodesource.com/setup_${NODE_VERSION}.x | bash - \ && apt-get install -y nodejs \ && npm install -g npm COPY . ${APP_DIR} # Install packages for the application RUN npm install --only=prod \ && apt-get autoremove -y curl make gcc g++ python3 git \ && apt-get purge -y \ && rm -rf /var/lib/apt/lists/* \ && chmod a+rx ${APP_DIR}/* # Stage 2: Runtime FROM node:16-slim as clientAppImage ENV APP_DIR /usr/local/clientapp WORKDIR ${APP_DIR} # Copy built application from the builder stage COPY --from=builder ${APP_DIR}/ ${APP_DIR} # Copy the MQ configuration files COPY ccdt/FOO_BAR.TAB ${APP_DIR}/mqconfig/FOO_BAR.TAB # Set environment variables for MQ ENV MQCHLLIB=${APP_DIR}/mqconfig ENV MQCHLTAB=FOO_BAR.tab ENV CCDTURL=file://${APP_DIR}/mqconfig/FOO_BAR.tab EXPOSE 8080 CMD npm start
MQ连接代码片段
approutes.js
const inboundQueueName = "SOME.INBOUND.QUEUE"; let mqclientInbound = new MQClient(inboundQueueName);
mqclient.js
constructor(queueName) { this[_HCONNKEY] = null; this[_HOBJKEY] = null; this._queueName = queueName; } performConnection() { return new Promise((resolve, reject) => { this.buildCNO() .then((cno) => { debug_info("CNO Built"); return mq.ConnxPromise(MQDetails.QMGR, cno); }) .then((hconn) => { debug_info("Connected to MQ"); this[_HCONNKEY] = hconn; return this.performOpen(); }) .then((hObj) => { debug_info("MQ Queue is open"); this[_HOBJKEY] = hObj; resolve(); }) .catch((err) => { debug_warn("Error establishing connection to MQ"); debug_warn(err); reject(err); }); }); debug_info("Establishing Connection to MQ"); } performOpen() { let od = new mq.MQOD(); od.ObjectName = this._queueName; od.ObjectType = MQC.MQOT_Q; let openOptions = MQC.MQOO_OUTPUT | MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_BROWSE; debug_info("Performing open", this[_HCONNKEY]); return mq.OpenPromise(this[_HCONNKEY], od, openOptions); //<--- FAILING HERE }
已尝试的调试步骤
- 文件存在性:已验证容器中存在.tab文件
- 文件名大小写:确保文件名大小写一致
- 代码调试:添加额外日志以确认错误发生位置
- 客户端与服务器:确认仅使用客户端连接,无需本地队列管理器连接
尽管执行了上述步骤,应用仍遇到授权错误。
求助需求
- 授权:连接远程IBM MQ服务器时,需额外执行哪些步骤来解决MQRC_NOT_AUTHORIZED错误?
- 配置:是否需要调整Dockerfile或应用代码中的特定配置以正确授权连接?
内容的提问来源于stack exchange,提问作者Uhnj
相关产品推荐
相关产品推荐

