IBM MQ 同步点和 dotnet
IBM MQ syncpoint and dotnet
尝试使用 c# 和 ibm mq 客户端 (9.1.5) 时,我想使用同步点功能。
var getMessageOptions = new MQGetMessageOptions();
getMessageOptions = new MQGetMessageOptions();
getMessageOptions.Options += MQC.MQGMO_WAIT + MQC.MQGMO_SYNCPOINT;
getMessageOptions.WaitInterval = 20000; // 20 seconds wait
Hashtable props = new Hashtable();
props.Add(MQC.HOST_NAME_PROPERTY, "localhost");
props.Add(MQC.CHANNEL_PROPERTY, "DOTNET.SVRCONN");
props.Add(MQC.PORT_PROPERTY, 3636);
MQQueueManager qm = new MQQueueManager("QM", props);
MQQueue queue = qm.AccessQueue("Q1", MQC.MQOO_INPUT_AS_Q_DEF);
try
{
var message = new MQMessage();
queue.Get(message, getMessageOptions);
string messageStr = message.ReadString(message.DataLength);
SaveTheMessageToAFile(messageStr);
//qm.Commit();
}
catch (MQException e) when (e.Reason == 2033)
{
// Report exceptions other than "no messages in the queue"
Log.Information("No messages in the queue");
}
catch (Exception ex)
{
Log.Error($"Exception when trying to capture a message from the queue:
}
如果我不调用 commit,我本以为每次都会看到相同的消息。队列管理器是否需要启用某些功能?
在您的示例中,您没有发出 Commit()
或 Backout()
,因此此时消息将处于未提交状态。如果您随后终止进程,消息将回滚到队列中。正如您在评论中提到的,如果您调用 Disconnect()
,在大多数情况下,这将隐式提交未提交的消息。
这在 IBM MQ KC 的几页中有记录:
Disconnect();
...
Generally, any work performed as part of a unit of work is committed. However, if the unit of work is managed by .NET
, the unit of work might be rolled back.
注意: managed by .NET
表示分布式事务,而不是你在做什么。
Developing applications>Developing .NET applications
When you use the procedural interface, you disconnect from a queue manager by using the call MQDISC
( Hconn, CompCode, Reason)
, where Hconn
is a handle to the queue manager.
In the .NET interface, the queue manager is represented by an object of class MQQueueManager. You disconnect from the queue manager by calling the Disconnect()
method on that class.
Except on z/OS batch with RRS, if a program issues the MQDISC call while there are uncommitted requests, an implicit syncpoint occurs. If the program ends abnormally, an implicit backout occurs.
尝试使用 c# 和 ibm mq 客户端 (9.1.5) 时,我想使用同步点功能。
var getMessageOptions = new MQGetMessageOptions();
getMessageOptions = new MQGetMessageOptions();
getMessageOptions.Options += MQC.MQGMO_WAIT + MQC.MQGMO_SYNCPOINT;
getMessageOptions.WaitInterval = 20000; // 20 seconds wait
Hashtable props = new Hashtable();
props.Add(MQC.HOST_NAME_PROPERTY, "localhost");
props.Add(MQC.CHANNEL_PROPERTY, "DOTNET.SVRCONN");
props.Add(MQC.PORT_PROPERTY, 3636);
MQQueueManager qm = new MQQueueManager("QM", props);
MQQueue queue = qm.AccessQueue("Q1", MQC.MQOO_INPUT_AS_Q_DEF);
try
{
var message = new MQMessage();
queue.Get(message, getMessageOptions);
string messageStr = message.ReadString(message.DataLength);
SaveTheMessageToAFile(messageStr);
//qm.Commit();
}
catch (MQException e) when (e.Reason == 2033)
{
// Report exceptions other than "no messages in the queue"
Log.Information("No messages in the queue");
}
catch (Exception ex)
{
Log.Error($"Exception when trying to capture a message from the queue:
}
如果我不调用 commit,我本以为每次都会看到相同的消息。队列管理器是否需要启用某些功能?
在您的示例中,您没有发出 Commit()
或 Backout()
,因此此时消息将处于未提交状态。如果您随后终止进程,消息将回滚到队列中。正如您在评论中提到的,如果您调用 Disconnect()
,在大多数情况下,这将隐式提交未提交的消息。
这在 IBM MQ KC 的几页中有记录:
Disconnect();
...
Generally, any work performed as part of a unit of work is committed. However, if the unit of work is
managed by .NET
, the unit of work might be rolled back.
注意: managed by .NET
表示分布式事务,而不是你在做什么。
Developing applications>Developing .NET applications
When you use the procedural interface, you disconnect from a queue manager by using the call
MQDISC
( Hconn, CompCode, Reason)
, whereHconn
is a handle to the queue manager.In the .NET interface, the queue manager is represented by an object of class MQQueueManager. You disconnect from the queue manager by calling the
Disconnect()
method on that class.
Except on z/OS batch with RRS, if a program issues the MQDISC call while there are uncommitted requests, an implicit syncpoint occurs. If the program ends abnormally, an implicit backout occurs.