azure service bus duplicate detection

 

Azure service bus duplicate detection works by using messageId as a unique identifier. If a sender tries to send messages with the same messageId, the first one gets into the queue. The other subsequent duplicate messageId will be ignored. 


// create the sender
ServiceBusSender sender = client.CreateSender(queueName);
// create a message batch that we can send
ServiceBusMessageBatch messageBatch = await sender.CreateMessageBatchAsync();
messageBatch.TryAddMessage(
    new ServiceBusMessage("Session1-1")
    {
        MessageId = "Session1"
    });
messageBatch.TryAddMessage(
    new ServiceBusMessage("Session1-3")
    {
        MessageId = "Session1"
    });

messageBatch.TryAddMessage(
    new ServiceBusMessage("Session1-2")
    {
        MessageId = "Session1"
    });

// send the messages
await sender.SendMessagesAsync(messageBatch);

// Message Session1-1 gets into the queue
// Message Session1-2 and Session1-3 ignored

Console.WriteLine("Done sending messages.");




Comments

Popular posts from this blog

The specified initialization vector (IV) does not match the block size for this algorithm