I have a problem due to which a message is sometimes read from Q more than once. I use the .NET wrapper for MQSeries (amqmdnet.dll) and read messages using Win Service.
Here how I do it with VB.NET:
'QManager
Dim properties As Hashtable = New Hashtable(4)
properties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_CLIENT)
properties.Add(MQC.CHANNEL_PROPERTY, channelName)
properties.Add(MQC.HOST_NAME_PROPERTY, iPAddress)
properties.Add(MQC.PORT_PROPERTY, port)
QManager = New MQQueueManager(queueManagerName, _
properties)
'Q itself
getMessageOptions.Options = _
MQC.MQGMO_FAIL_IF_QUIESCING Or _
MQC.MQGMO_WAIT Or _
MQC.MQGMO_SYNCPOINT
getMessageOptions.WaitInterval = 1000 ' read from config
Dim locker As New Object
System.Threading.Monitor.Enter(locker)
Q.Get(message, getMessageOptions)
QManager.Commit()
System.Threading.Monitor.Exit(locker)
I heard that Q.Get (message, getMessageOptions) makes the message inaccessible to other readers, QManager.Commit, in turn, simply removes the message from Q (similar to .NET Peek and Dequeue). This alone should eliminate the need for a Monitor.
In my Win service, several threads read Q, and we suspect that due to the low polling interval (100 ms or less), the wrapper does not receive enough time to update the Read flag of the message, so it is received more than once, blocking the threads. Historically, the same message is read up to four times.
, , . - - ?
.
user572559