I am new to azure service bus, I am supposed to push messages to a queue and then have a separate scheduled task that will read all active messages in this queue and bulk import them to sql I tried this code before and it was working when I called it right after sending the message but now its not working within the separate scheduled task. Any help why or what i can use to batch read the messages or that's not possible
queueClient = new QueueClient(conn, queuename, ReceiveMode.ReceiveAndDelete);
var messageHandlerOptions = new MessageHandlerOptions(ExceptionReceivedHandler)
{
MaxConcurrentCalls = 1,
AutoComplete = false
};
queueClient.RegisterMessageHandler(ReceiveMessagesAsync, messageHandlerOptions);
public async Task ReceiveMessagesAsync(Message message, CancellationToken token)
{
messages.Add(message.Body.ToString());
Console.WriteLine($"Received message: {Encoding.UTF8.GetString(message.Body)}");
await queueClient.CompleteAsync(message.SystemProperties.LockToken);
}
public Task ExceptionReceivedHandler(ExceptionReceivedEventArgs exceptionReceivedEventArgs)
{
Console.WriteLine(exceptionReceivedEventArgs.Exception);
return Task.CompletedTask;
}