I want to be sure that if same message is already present in the queue then second message should be ignored.(not inserted to queue) while webjob
is
processing first message.
I tried following code:
var namespaceManager =
NamespaceManager.CreateFromConnectionString(connectionString);
if (!namespaceManager.QueueExists(queueName))
{
namespaceManager.CreateQueue(new QueueDescription(queueName) { RequiresDuplicateDetection = true });
}
property RequiresDuplicateDetection
should
insure about duplicate message.
// Get messageFactory for runtime operation
MessagingFactory messagingFactory = MessagingFactory.CreateFromConnectionString(connectionString);
QueueClient queueClient = messagingFactory.CreateQueueClient("TestQueue");
BrokeredMessage message = new BrokeredMessage();
message.MessageId = "Localization";
queueClient.Send(message);
But webjob
gets trigger
for every messageId
. I gave sleep
time 150000 MILI SEC
but before that I tried to insert
same message to same queue
, which should not be inserted because of duplicate message.
tried msdn MSDN LINK but it is not working in Azure Webjob Any one can help me in this?
WebJob Code :
public static void ProcessQueueMessage([ServiceBusTrigger("TestQueue")] BrokeredMessage message, TextWriter log)
{
log.WriteLine("Webjob Start" + message.MessageId + DateTime.Now);
Thread.Sleep(150000);
log.WriteLine("Webjob End" + message.MessageId + DateTime.Now);
}
Ashish (ashuthinksatgmail.com) SE