venkatesh chava

venkatesh chava

  • NA
  • 77
  • 1.7k

Azure Service Bus

Jul 11 2019 7:31 AM
 I just Want to send  a message to Azure Service Bus  With delayed process at particular time   eg: after 2 hrs . how i can archive that please povide me an  example. Thanks in advance.
 
So far i did like this but i am unable send the message to queue.  i am getting status as Faulted. 
 
public class ServiceBusQueueHelpers
{
string serviceBusConnectionString = "my Queue Connectionstring";
string sbQueueName = "Test Queue";
DateTime utcEnqueueTime = DateTime.UtcNow;
public static Microsoft.Azure.ServiceBus.QueueClient queueClient;
public async Task SendDelayedMessageAsync(string queue, string message, string serviceBusConnectionString, DateTime utcEnqueueTime)
{
ServiceBusConnectionStringBuilder sb = new ServiceBusConnectionStringBuilder(serviceBusConnectionString);
for (int i = 0; i < 2; i++)
{
Message queueMessage = new Message(Encoding.UTF8.GetBytes(message));
queueMessage.ScheduledEnqueueTimeUtc = utcEnqueueTime.AddSeconds(120);
Microsoft.Azure.ServiceBus.QueueClient client = new Microsoft.Azure.ServiceBus.QueueClient(sb, Microsoft.Azure.ServiceBus.ReceiveMode.ReceiveAndDelete);
await client.SendAsync(queueMessage);
await client.CloseAsync();
}
}
}

Answers (2)