Are the features below supported by IBM Websphere MQ in .NET client? Please provide code example.
1. Publisher Confirms
When Publisher sends messages to queue, it receives confirmations from MQ server that messages have been saved to hard disk.
Does MQ server save message before sending confirmation?
Update 2
Is it corrent that when MQQueue.Put() returns, the message has been saved to transaction log? How long does it take to save to disk? What about message persistence in a cluster?
void PutMessage(byte[] messageString)
{
try{
// creating a message object
message = new MQMessage();
message.Write(messageString);
message.Format = MQC.MQFMT_STRING;
message.CharacterSet = 1208;// IbmUtf8Encoding;
message.Persistence = MQC.MQPER_PERSISTENT;
var options = new MQPutMessageOptions
{
Options = useSyncPoint ? MQC.MQPMO_SYNCPOINT : MQC.MQPMO_NO_SYNCPOINT
};
queue.Put(message, options);
qMgr.Commit();
}catch(Exception e){
qMgr.Backout();
}
}
2. Consumer Acknowledgement
When Consumer receives messages from queue, processes them, then sends acknowledgement to MQ server.
Update 3
How can Consumer acknowledges to MQ server that messages have been processed successfully, and the messages can be safely deleted from server?
public void GetMessages()
{
Open(ConnectionMode.Read);
for (int i = 1; i <= numberOfMsgs; i++)
{
GetMessage();
}
queue.Close();
queueManager.Disconnect();
}
public string GetMessage()
{
message = new MQMessage { Format = MQC.MQFMT_STRING };
var mqMessageOptions = new MQGetMessageOptions
{
Options = MQC.MQGMO_WAIT | MQC.MQGMO_FAIL_IF_QUIESCING | MQC.MQGMO_SYNCPOINT
};
queue.Get(message, mqMessageOptions, MaxMessageSizeInBytes);
var content = message.ReadString(message.MessageLength);
message.ClearMessage();
return content;
}
public void Open(ConnectionMode websphereConnectionMode)
{
var connectionSettings = new Hashtable
{
{MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED },
{MQC.CONNECT_OPTIONS_PROPERTY, MQC.MQCNO_RECONNECT }
};
int openOptions = 0;
switch (websphereConnectionMode)
{
case ConnectionMode.Read:
openOptions = MQC.MQOO_INPUT_SHARED + MQC.MQOO_FAIL_IF_QUIESCING;
break;
case ConnectionMode.Write:
openOptions = MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING;
break;
}
queueManager = new MQQueueManager(queueManagerName);
queue = queueManager.AccessQueue(queueName, openOptions);
}
public enum ConnectionMode
{
Read,
Write
}
How to do an explicit ACK when receiving Websphere MQ messages?