如何在 IBM MQ .on Net Core 平台上使用回退和提交
How Can I Use Backout and Commit at IBM MQ .on Net Core Platform
我想在 IBM MQ 客户端使用回退和提交。
处理订单
- 将 10 条消息放入队列
- 从队列中获取 10 条消息并 Backout()
由于回退,我预计队列中存在 10 条消息,但队列中不存在任何消息。所以我认为 Backout 不能正常工作。为什么?
平台:.Net Core 2.1
IBM 客户端 DLL:amqmdnetstd.dll v 9.1.2
代码
string hostName = "TX32";
int port = 5566;
string channelName = "TESTTRY";
string queueName = "TESTTRY";
int numberOfMsgs = 10;
string queueManagerName = "DMQ1";
int queueOpenOptionsForPut = MQC.MQOO_OUTPUT + MQC.MQGMO_SYNCPOINT + MQC.MQOO_FAIL_IF_QUIESCING;
int queueOpenOptionsForGet = MQC.MQGMO_SYNCPOINT + MQC.MQOO_FAIL_IF_QUIESCING;
string messageString = "Bunyamin Test";
MQQueue queue;
properties = new Hashtable();
properties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);
properties.Add(MQC.HOST_NAME_PROPERTY, hostName);
properties.Add(MQC.PORT_PROPERTY, port);
properties.Add(MQC.CHANNEL_PROPERTY, channelName);
// PUT MESSAGES
var queueManager = new MQQueueManager(queueManagerName, properties);
queue = queueManager.AccessQueue(queueName, queueOpenOptionsForPut);
var message = new MQMessage();
message.WriteString(messageString);
// putting messages continuously
for (var i = 1; i <= numberOfMsgs; i++)
{
System.Console.Write("Message " + i + " <" + messageString + ">.. ");
queue.Put(message);
System.Console.WriteLine("put");
}
queue.Close();
queueManager.Disconnect();
//GET MESSAGES
queueManager = new MQQueueManager(queueManagerName, properties);
queue = queueManager.AccessQueue(queueName, queueOpenOptionsForGet);
for (var i = 1; i <= numberOfMsgs; i++)
{
// creating a message object
message = new MQMessage();
queue.Get(message);
System.Console.WriteLine(i + " .Message " + i + " got = " +
message.ReadString(message.MessageLength));
queueManager.Backout(); //I EXPECT 10 MESSAGES SHOULD GO BACK TO QUEUE?
message.ClearMessage();
}
queue.Close();
queueManager.Disconnect();
您已将 PMO/GMO 标志与 OO 标志混合(并将 GMO 放在 PutOpen ...)
GMO 标志需要在 Get 上,而不是 Open 上。对于 PMO 标志也是如此。
我会这样修改你的申请。
void testCommitBackout()
{
string hostName = "localhost";
int port = 1414;
string channelName = "SVRCONN_CHN";
string queueName = "QU1";
int numberOfMsgs = 10;
string queueManagerName = "QM1";
int queueOpenOptionsForPut = MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING;
int queueOpenOptionsForGet = MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING;
string messageString = "Bunyamin Test";
MQQueue queue;
Hashtable properties = new Hashtable();
properties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);
properties.Add(MQC.HOST_NAME_PROPERTY, hostName);
properties.Add(MQC.PORT_PROPERTY, port);
properties.Add(MQC.CHANNEL_PROPERTY, channelName);
properties.Add(MQC.USER_ID_PROPERTY, "myuserid");
properties.Add(MQC.PASSWORD_PROPERTY, "Mylongpassword");
// PUT MESSAGES
var queueManager = new MQQueueManager(queueManagerName, properties);
queue = queueManager.AccessQueue(queueName, queueOpenOptionsForPut);
// putting messages continuously under a syncpoint and commit after that
for (var i = 1; i <= numberOfMsgs; i++)
{
var mqpmo = new MQPutMessageOptions();
mqpmo.Options |= MQC.MQPMO_SYNCPOINT;
var message = new MQMessage();
message.WriteString(messageString);
System.Console.Write("Message " + i + " <" + messageString + ">.. ");
queue.Put(message, mqpmo);
System.Console.WriteLine("put");
}
// Now commit all 10 messages.
queueManager.Commit();
queue.Close();
queueManager.Disconnect();
//GET MESSAGES
queueManager = new MQQueueManager(queueManagerName, properties);
queue = queueManager.AccessQueue(queueName, queueOpenOptionsForGet);
// Get messages under syncpoint
for (var i = 1; i <= numberOfMsgs; i++)
{
// creating a message object
var message = new MQMessage();
var gmo = new MQGetMessageOptions();
gmo.Options |= MQC.MQGMO_SYNCPOINT;
queue.Get(message, gmo);
System.Console.WriteLine(i + " .Message " + i + " got = " +
message.ReadString(message.MessageLength));
message.ClearMessage();
}
// Backout all messages.
queueManager.Backout(); //I EXPECT 10 MESSAGES SHOULD GO BACK TO QUEUE?
queue.Close();
queueManager.Disconnect();
}
希望对您有所帮助。
我想在 IBM MQ 客户端使用回退和提交。
处理订单
- 将 10 条消息放入队列
- 从队列中获取 10 条消息并 Backout() 由于回退,我预计队列中存在 10 条消息,但队列中不存在任何消息。所以我认为 Backout 不能正常工作。为什么?
平台:.Net Core 2.1
IBM 客户端 DLL:amqmdnetstd.dll v 9.1.2
代码
string hostName = "TX32";
int port = 5566;
string channelName = "TESTTRY";
string queueName = "TESTTRY";
int numberOfMsgs = 10;
string queueManagerName = "DMQ1";
int queueOpenOptionsForPut = MQC.MQOO_OUTPUT + MQC.MQGMO_SYNCPOINT + MQC.MQOO_FAIL_IF_QUIESCING;
int queueOpenOptionsForGet = MQC.MQGMO_SYNCPOINT + MQC.MQOO_FAIL_IF_QUIESCING;
string messageString = "Bunyamin Test";
MQQueue queue;
properties = new Hashtable();
properties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);
properties.Add(MQC.HOST_NAME_PROPERTY, hostName);
properties.Add(MQC.PORT_PROPERTY, port);
properties.Add(MQC.CHANNEL_PROPERTY, channelName);
// PUT MESSAGES
var queueManager = new MQQueueManager(queueManagerName, properties);
queue = queueManager.AccessQueue(queueName, queueOpenOptionsForPut);
var message = new MQMessage();
message.WriteString(messageString);
// putting messages continuously
for (var i = 1; i <= numberOfMsgs; i++)
{
System.Console.Write("Message " + i + " <" + messageString + ">.. ");
queue.Put(message);
System.Console.WriteLine("put");
}
queue.Close();
queueManager.Disconnect();
//GET MESSAGES
queueManager = new MQQueueManager(queueManagerName, properties);
queue = queueManager.AccessQueue(queueName, queueOpenOptionsForGet);
for (var i = 1; i <= numberOfMsgs; i++)
{
// creating a message object
message = new MQMessage();
queue.Get(message);
System.Console.WriteLine(i + " .Message " + i + " got = " +
message.ReadString(message.MessageLength));
queueManager.Backout(); //I EXPECT 10 MESSAGES SHOULD GO BACK TO QUEUE?
message.ClearMessage();
}
queue.Close();
queueManager.Disconnect();
您已将 PMO/GMO 标志与 OO 标志混合(并将 GMO 放在 PutOpen ...) GMO 标志需要在 Get 上,而不是 Open 上。对于 PMO 标志也是如此。
我会这样修改你的申请。
void testCommitBackout()
{
string hostName = "localhost";
int port = 1414;
string channelName = "SVRCONN_CHN";
string queueName = "QU1";
int numberOfMsgs = 10;
string queueManagerName = "QM1";
int queueOpenOptionsForPut = MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING;
int queueOpenOptionsForGet = MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING;
string messageString = "Bunyamin Test";
MQQueue queue;
Hashtable properties = new Hashtable();
properties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);
properties.Add(MQC.HOST_NAME_PROPERTY, hostName);
properties.Add(MQC.PORT_PROPERTY, port);
properties.Add(MQC.CHANNEL_PROPERTY, channelName);
properties.Add(MQC.USER_ID_PROPERTY, "myuserid");
properties.Add(MQC.PASSWORD_PROPERTY, "Mylongpassword");
// PUT MESSAGES
var queueManager = new MQQueueManager(queueManagerName, properties);
queue = queueManager.AccessQueue(queueName, queueOpenOptionsForPut);
// putting messages continuously under a syncpoint and commit after that
for (var i = 1; i <= numberOfMsgs; i++)
{
var mqpmo = new MQPutMessageOptions();
mqpmo.Options |= MQC.MQPMO_SYNCPOINT;
var message = new MQMessage();
message.WriteString(messageString);
System.Console.Write("Message " + i + " <" + messageString + ">.. ");
queue.Put(message, mqpmo);
System.Console.WriteLine("put");
}
// Now commit all 10 messages.
queueManager.Commit();
queue.Close();
queueManager.Disconnect();
//GET MESSAGES
queueManager = new MQQueueManager(queueManagerName, properties);
queue = queueManager.AccessQueue(queueName, queueOpenOptionsForGet);
// Get messages under syncpoint
for (var i = 1; i <= numberOfMsgs; i++)
{
// creating a message object
var message = new MQMessage();
var gmo = new MQGetMessageOptions();
gmo.Options |= MQC.MQGMO_SYNCPOINT;
queue.Get(message, gmo);
System.Console.WriteLine(i + " .Message " + i + " got = " +
message.ReadString(message.MessageLength));
message.ClearMessage();
}
// Backout all messages.
queueManager.Backout(); //I EXPECT 10 MESSAGES SHOULD GO BACK TO QUEUE?
queue.Close();
queueManager.Disconnect();
}
希望对您有所帮助。