我正在尝试使用来自Asp.net的Web Sphere MQ在队列管理器中放置和获取消息。以下是我的代码。我收到错误2033 MQRC_NO_MSG_AVAILABLE我从队列中读取消息时做错了什么。提前感谢
using System;
using System.Collections.Generic;
using System.Text;
using IBM.WMQ;
using System.Collections;
namespace JMS_IBM
{
class Program
{
const String connectionType = MQC.TRANSPORT_MQSERIES_CLIENT;
// Define the name of the queue manager to use (applies to all connections)
const String qManager = "XXXXX";
// Define the name of your host connection (applies to client connections only)
const String hostName = "XX.XX.XX.XX(XXXX)";
// Define the name of the channel to use (applies to client connections only)
const String channel = "SYSTEM.DEF.SVRCONN";
static Hashtable init(String connectionType)
{
Hashtable connectionProperties = new Hashtable();
// Add the connection type
connectionProperties.Add(MQC.TRANSPORT_PROPERTY, connectionType);
// Set up the rest of the connection properties, based on the
// connection type requested
switch (connectionType)
{
case MQC.TRANSPORT_MQSERIES_BINDINGS:
break;
case MQC.TRANSPORT_MQSERIES_CLIENT:
case MQC.TRANSPORT_MQSERIES_XACLIENT:
case MQC.TRANSPORT_MQSERIES_MANAGED:
connectionProperties.Add(MQC.HOST_NAME_PROPERTY, hostName);
connectionProperties.Add(MQC.CHANNEL_PROPERTY, channel);
break;
}
return connectionProperties;
}
static int Main(string[] args)
{
try
{
Hashtable connectionProperties = init(connectionType);
// Create a connection to the queue manager using the connection
// properties just defined
MQQueueManager qMgr = new MQQueueManager(qManager, connectionProperties);
// Set up the options on the queue we want to open
int openOptions = MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING;
//MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
// Now specify the queue that we want to open,and the open options
MQQueue system_default_local_queue =
qMgr.AccessQueue("SC.CRM.SVC.RQI.01", openOptions);
// Define a WebSphere MQ message, writing some text in UTF format
MQMessage hello_world = new MQMessage();
//hello_world.WriteUTF("Hello World!");
//01244269211
string msg = "XML";
hello_world.WriteString(msg);
// Specify the message options
MQPutMessageOptions pmo = new MQPutMessageOptions(); // accept the defaults,
// same as MQPMO_DEFAULT
// Put the message on the queue
system_default_local_queue.Put(hello_world, pmo);
hello_world.CorrelationId = hello_world.MessageId;
//retrievedMessage.CorrelationId = hello_world.MessageId;
// Set the get message options
MQGetMessageOptions gmo = new MQGetMessageOptions(); //accept the defaults
//same as MQGMO_DEFAULT
int readOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_FAIL_IF_QUIESCING;
MQQueue system_default_local_queue_OT = qMgr.AccessQueue("SC.CRM.SVC.RPO.01", readOptions);
gmo.Options = MQC.MQGMO_WAIT | MQC.MQOO_FAIL_IF_QUIESCING;
//gmo.MatchOptions = MQC.MQMO_MATCH_CORREL_ID;
gmo.MatchOptions = MQC.MQMO_NONE;
gmo.WaitInterval = 5000;
// retrievedMessage.CorrelationId = retrievedMessage.MessageId;
// Get the message off the queue
system_default_local_queue_OT.Get(hello_world, gmo);
// Prove we have the message by displaying the UTF message text
String msgText = hello_world.ReadUTF();
Console.WriteLine("The message is: {0}", msgText);
// Close the queue
system_default_local_queue.Close();
// Disconnect from the queue manager
qMgr.Disconnect();
}
catch (MQException ex)
{
Console.WriteLine("A WebSphere MQ error occurred: {0}", ex.ToString());
}
catch (System.Exception ex)
{
Console.WriteLine("A System error occurred: {0}", ex.ToString());
}
return 0;
}//end of start
}
}
答案 0 :(得分:0)
如你所知2033 0x000007f1 MQRC_NO_MSG_AVAILABLE ..所以你所做的一切似乎都是正确的但是队列管理器方面的Q似乎没有msg ..请确认你是否在Q中有msg仍然得到这个?