如何编写脚本来复制 IBM MQ MQExplorer object 创建行为?

How do I write a script to duplicate IBM MQ MQExplorer object creation behavior?

使用 IBM MQ 8.0.0.9 我无法从命令行复制 MQExplorer GUI 操作的行为。

使用 MQExplorer 我创建:

  1. 一位名为 testQueueManager 的 Queue 经理使用默认值
  2. 标题为 testQueue 的 Queue 使用默认值
  3. 标题为 testChannel 的 Server-connection 频道使用默认值
  4. 使用 * 地址映射的通道认证记录 -> 用户 ID client

Java 客户端连接到该实例没有问题。

下面的 shell 脚本应该根据我所知道的复制上面的内容。我知道我授予了不必要的权限,这纯粹是为了连接测试。

#!/bin/sh
set -eu
user=client
pass=password
qmgr="testQueueManager"
channel="testChannel"
queue="testQueue"

useradd "$user" && echo "$user":password | chpasswd
/opt/mqm/bin/crtmqm "$qmgr"
/opt/mqm/bin/strmqm "$qmgr"
/opt/mqm/bin/runmqsc "$qmgr" << EOF
DEFINE QLOCAL('$queue')
DEFINE CHANNEL('$channel') CHLTYPE(SVRCONN) TRPTYPE(TCP)
SET CHLAUTH('$channel') TYPE(ADDRESSMAP) ADDRESS('*') USERSRC(MAP) MCAUSER('$user') ACTION(ADD)
EOF

/opt/mqm/bin/setmqaut -m "$qmgr" -t qmgr -p client +all
/opt/mqm/bin/setmqaut -m "$qmgr" -n "$channel" -t channel -p client +all
/opt/mqm/bin/setmqaut -m "$qmgr" -n "$queue"  -t queue -p client +all

这是 shell 脚本在我 运行 时的输出:

WebSphere MQ queue manager created.
Directory '/var/mqm/qmgrs/testQueueManager' created.
The queue manager is associated with installation 'Installation1'.
Creating or replacing default objects for queue manager 'testQueueManager'.
Default objects statistics : 79 created. 0 replaced. 0 failed.
Completing setup.
Setup completed.
WebSphere MQ queue manager 'testQueueManager' starting.
The queue manager is associated with installation 'Installation1'.
5 log records accessed on queue manager 'testQueueManager' during the log replay phase.
Log replay for queue manager 'testQueueManager' complete.
Transaction manager state recovered for queue manager 'testQueueManager'.
WebSphere MQ queue manager 'testQueueManager' started using V8.0.0.9.
5724-H72 (C) Copyright IBM Corp. 1994, 2015.
Starting MQSC for queue manager testQueueManager.


     1 : DEFINE QLOCAL('testQueue')
AMQ8006: WebSphere MQ queue created.
     2 : DEFINE CHANNEL('testChannel') CHLTYPE(SVRCONN) TRPTYPE(TCP)
AMQ8014: WebSphere MQ channel created.
     3 : SET CHLAUTH('testChannel') TYPE(ADDRESSMAP) ADDRESS('*') USERSRC(MAP) MCAUSER('client') ACTION(ADD)
AMQ8877: WebSphere MQ channel authentication record set.
3 MQSC commands read.
No commands have a syntax error.
All valid MQSC commands were processed.
The setmqaut command completed successfully.
The setmqaut command completed successfully.
The setmqaut command completed successfully.

我希望连接到相同项目的 Java 客户端具有相同的行为。我得到的是如下令人讨厌的堆栈跟踪:

org.apache.felix.log.LogException: com.ibm.msg.client.jms.DetailedJMSException: JMSWMQ0018: Failed to connect to queue manager 'testQueueManager' with connection mode 'Client' and host name '127.0.0.1(1414)'.
        at com.ibm.msg.client.wmq.common.internal.Reason.reasonToException(Reason.java:595)
        at com.ibm.msg.client.wmq.common.internal.Reason.createException(Reason.java:215)
        at com.ibm.msg.client.wmq.internal.WMQConnection.<init>(WMQConnection.java:423)
        at com.ibm.msg.client.wmq.factories.WMQConnectionFactory.createV7ProviderConnection(WMQConnectionFactory.java:8475)
        at com.ibm.msg.client.wmq.factories.WMQConnectionFactory.createProviderConnection(WMQConnectionFactory.java:7814)
        at com.ibm.msg.client.jms.admin.JmsConnectionFactoryImpl._createConnection(JmsConnectionFactoryImpl.java:299)
        at com.ibm.msg.client.jms.admin.JmsConnectionFactoryImpl.createConnection(JmsConnectionFactoryImpl.java:236)
        at com.ibm.mq.jms.MQConnectionFactory.createCommonConnection(MQConnectionFactory.java:6016)
        at com.ibm.mq.jms.MQConnectionFactory.createConnection(MQConnectionFactory.java:6041)
        ... 7 more
Caused by: org.apache.felix.log.LogException: com.ibm.mq.MQException: JMSCMQ0001: WebSphere MQ call failed with compcode '2' ('MQCC_FAILED') reason '2009' ('MQRC_CONNECTION_BROKEN').
        at com.ibm.msg.client.wmq.common.internal.Reason.createException(Reason.java:203)
        ... 15 more
Caused by: org.apache.felix.log.LogException: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2009;AMQ9204: Connection to host '127.0.0.1(1414)' rejected. [1=com.ibm.mq.jmqi.JmqiException[CC=2;RC=2009;AMQ9208: Error on receive from host '/127.0.0.1:1414 (localhost)'. [1=-1,2=ffffffff,3=/127.0.0.1:1414 (localhost),4=TCP]],3=127.0.0.1(1414),5=RemoteConnection.receiveTSH]
        at com.ibm.mq.jmqi.remote.api.RemoteFAP.jmqiConnect(RemoteFAP.java:2276)
        at com.ibm.mq.jmqi.remote.api.RemoteFAP.jmqiConnect(RemoteFAP.java:1288)
        at com.ibm.mq.ese.jmqi.InterceptedJmqiImpl.jmqiConnect(InterceptedJmqiImpl.java:376)
        at com.ibm.mq.ese.jmqi.ESEJMQI.jmqiConnect(ESEJMQI.java:560)
        at com.ibm.msg.client.wmq.internal.WMQConnection.<init>(WMQConnection.java:356)
        ... 14 more
Caused by: org.apache.felix.log.LogException: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2009;AMQ9208: Error on receive from host '/127.0.0.1:1414 (localhost)'. [1=-1,2=ffffffff,3=/127.0.0.1:1414 (localhost),4=TCP]
        at com.ibm.mq.jmqi.remote.impl.RemoteConnection.receiveTSH(RemoteConnection.java:3291)
        at com.ibm.mq.jmqi.remote.impl.RemoteConnection.initSess(RemoteConnection.java:1411)
        at com.ibm.mq.jmqi.remote.impl.RemoteConnection.connect(RemoteConnection.java:1007)
        at com.ibm.mq.jmqi.remote.impl.RemoteConnectionSpecification.getSessionFromNewConnection(RemoteConnectionSpecification.java:409)
        at com.ibm.mq.jmqi.remote.impl.RemoteConnectionSpecification.getSession(RemoteConnectionSpecification.java:305)
        at com.ibm.mq.jmqi.remote.impl.RemoteConnectionPool.getSession(RemoteConnectionPool.java:155)
        at com.ibm.mq.jmqi.remote.api.RemoteFAP.jmqiConnect(RemoteFAP.java:1724)
        ... 18 more

This Question 似乎指向 jar 文件的差异,但我在这两种情况下都使用相同的客户端。似乎命令行与 MQExplorer.

的默认值必须有所不同

我看不到您在脚本中为队列管理器创建侦听器或在 crtmqm 命令上设置默认侦听器 (-p 1414)。在 MQ Explorer 中,创建队列管理器的步骤之一具有在端口 1414 上创建侦听器的默认设置。

要解决此问题:

将您的 crtmqm 命令更改为:crtmqm -p 1414 $qmgr

将以下 MQSC 命令添加到您的 runmqsc 命令中:

DEFINE LISTENER(LISTENER) TRPTYPE(TCP) PORT(1414)
START LISTENER(LISTENER)