I need to get messages from IBM MQ queue and put them into objects. So, I'm using the following code:
public MQMessage GetMessageFromQueue(string queueName)
{
MQMessage message = new MQMessage();
MQGetMessageOptions gmo = new MQGetMessageOptions();
var queueMngrForReading = new MQQueueManager(_managerName, _connectionParams);
var queue = queueMngrForReading.AccessQueue(queueName, MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING);
queue.Get(message, gmo);
System.Console.Out.WriteLine("Message Data: " + message.ReadString(message.MessageLength));
return message;
}
The problem is that when I call the method in Main using the following code:
MQClient mqClient = new MQClient();
mqClient.Connect(AppSettings.MQ.Manager);
string xml11 = mqClient.GetMessageFromQueue("PRQUEUE").ToString();
I get the values from my message displayed in Console, but the object xml11 gets the value "IBM.WMQ.MQMessage#013C8E0F".
How can I put the XML message in the object xml11?
Thanks.
With toString
you can not read the body of an MQMessage
.
I would change GetMessageFromQueue
like this:
public String GetMessageFromQueue(string queueName)
{
MQMessage message = new MQMessage();
MQGetMessageOptions gmo = new MQGetMessageOptions();
var queueMngrForReading = new MQQueueManager(_managerName, _connectionParams);
var queue = queueMngrForReading.AccessQueue(queueName, MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING);
queue.Get(message, gmo);
String msgText = message.ReadString(message.MessageLength);
System.Console.Out.WriteLine("Message Data: " + msgText)
return msgText;
}
To simplify your code, I recommend using the XMS API, see Developing XMS .NET applications .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.