我无法使用 java 读取来自 IBM MQ 的消息

I cant read the messages from IBM MQ using java

我使用的是 IBM MQ 7.5 版(试用版)

我创建了两个队列管理器(QM1 和 QM2)

QM1下:
端口:1421
队列:q1(本地队列)
频道:ch1(接收器)

QM2下:
端口:1422
Queues:q2(传输队列),q3(远程队列)
channel:ch1(发件人)

我可以通过 QM2 的队列 q3 将消息发送到 QM1 的队列队列 q1。我也可以通过q2.

接收和浏览消息

但是当我使用 java 从 q1 读取消息时出现错误

MQJE001: An MQException occurred: Completion Code 2, Reason 2009   
MQJE016: MQ queue manager closed channel immediately during connect    
Closure reason = 2009    
MQJE001: Completion Code 2, Reason 2009 

当我查看 IBM 网站时,他们说这可能会导致以下原因
http://www-01.ibm.com/support/docview.wss?uid=swg21226703

  1. 防火墙终止了连接。
  2. IOException 导致套接字关闭。
  3. 一个显式操作导致套接字被一端关闭。
  4. 队列管理器离线。
  5. 已打开队列管理器允许的最大通道数。
  6. 队列连接工厂 (QCF) 中的配置问题。

但以上所有在我的系统中看起来都不错。我遗漏了什么,请告诉我。

public static void main(String[] args) throws MQException {

MQEnvironment.hostname="localhost";
MQEnvironment.channel="ch1";
MQEnvironment.port=1421;
MQQueueManager qMgr= new MQQueueManager("QM1");
MQQueue outputQueue =qMgr.accessQueue("q1", MQC.MQOO_INQUIRE | MQC.MQOO_BROWSE | MQC.MQOO_INPUT_AS_Q_DEF);


//Checking for messages in queue
int i=outputQueue.getCurrentDepth();
System.out.println("Number of messages in  queue: "+i);


outputQueue.close();
qMgr.close();
qMgr.disconnect();
}

添加:

jar 版本:

C:\Program Files (x86)\IBM\WebSphere MQ\java\lib>java -cp ./com.ibm.mq.jar com.ibm.mq.MQJavaLevel
名称:WebSphere MQ 类 用于 Java
版本:7.5.0.2
等级:p750-002-130627
构建类型:生产

更改频道后我收到以下错误

    ----- amqrmrsa.c : 898 --------------------------------------------------------
10/20/2017 02:17:37 - Process(16340.40) User(MUSR_MQADMIN) Program(amqrmppa.exe)
                     Host(user1) Installation(Installation1)
                     VRMF(7.5.0.2) QMgr(Receiver)

AMQ9777: Channel was blocked

EXPLANATION:
The inbound channel 'SYSTEM.DEF.SVRCONN' was blocked from address '127.0.0.1'
because the active values of the channel matched a record configured with
USERSRC(NOACCESS). The active values of the channel were 'CLNTUSER(fresher)'.
ACTION:
Contact the systems administrator, who should examine the channel
authentication records to ensure that the correct settings have been
configured. The ALTER QMGR CHLAUTH switch is used to control whether channel
authentication records are used. The command DISPLAY CHLAUTH can be used to
query the channel authentication records. 
----- cmqxrmsa.c : 926 --------------------------------------------------------
10/20/2017 02:17:37 - Process(16340.40) User(MUSR_MQADMIN) Program(amqrmppa.exe)
                     Host(user1) Installation(Installation1)
                     VRMF(7.5.0.2) QMgr(Receiver)

AMQ9999: Channel 'SYSTEM.DEF.SVRCONN' to host 'user1 (127.0.0.1)' ended
abnormally.

EXPLANATION:
The channel program running under process ID 16340(5348) for channel
'SYSTEM.DEF.SVRCONN' ended abnormally. The host name is 'user1
(127.0.0.1)'; in some cases the host name cannot be determined and so is shown
as '????'.
ACTION:
Look at previous error messages for the channel program in the error logs to
determine the cause of the failure. Note that this message can be excluded
completely or suppressed by tuning the "ExcludeMessage" or "SuppressMessage"
attributes under the "QMErrorLog" stanza in qm.ini. Further information can be
found in the System Administration Guide. 
----- amqrmrsa.c : 898 --------------------------------------------------------

channel: ch1 (receiver)

MQEnvironment.channel="ch1";

MQ 客户端应用程序无法使用 RECEIVER 通道连接到队列管理器。应用程序需要连接到 SVRCONN 通道。

其次,对 MQ 对象使用小写名称不是一个好主意。 MQ 会自动将不在引号中的名称大写。因此,为避免出现问题,请使用大写名称。

终于解决了问题

  • By creating a svrconn channel instead of using default one SYSTEM.DEF.SVRCONN ( I have used TEST.SVRCONN )
  • And go to : channel -> Channel Authentication Records -> Delete the Block User list

按照上面的方法我可以解决问题。现在我可以阅读来自 Java 应用程序的消息。