In order to avoid this using queues you can use the session functionality of the Azure Service Bus.
You need to create a session aware queue first of all before you do anything else, which can be done as follows.
// Create a queue with duplicate detection
// with a detection history window of one hour,
// and requires sessions.
QueueDescription rfidCheckoutQueueDescription = new QueueDescription("rfidcheckout")
{
RequiresSession = true,
RequiresDuplicateDetection = true,
DuplicateDetectionHistoryTimeWindow = new TimeSpan(0, 1, 0)
};
// Create a queue that supports duplicate detection.
namespaceMgr.CreateQueue(rfidCheckoutQueueDescription);
When the session aware queue is setup you must set the SessionId
property for a message and recieve the message using MessageSession
instead of QueueClient
.
Some code samples can be found for this:
Sending Messages, Receiving Messages.