Azure Function with Service Bus Topic trigger to read messages

Ankit Kumar 91 Reputation points
2020-10-15T14:32:37.173+00:00

0

I have multiple message in my Service Bus Topic and I would like to process this message one by one and on a Service Bus Trigger, it should get all the messages which has not been processed. and since I am doing testing and debugging, I would not like the messages to be completed i.e. if it is not completed it stays in the topic for any other services to consume.

I have started with Azure Function App with Service Bus Topic Trigger and have moved up til here where I get all the message in my log but once it is done, I don't get any other messages because all have been consumed and they move to the "Dead-letter message count", so its become very difficult for me to do any debugging and testing.

I would like to know how can I handle this with Azure Function Service Bus trigger where I run the Function see the body of my message in console, exit it and then do the necessary transformation and then repeat the process. Without service bus trigger, I can do it with PeekLock thing and dont allow any message to be completed, but how do i do it with Function as it seems to take the messages at once for triggering.

 namespace ServiceBusCopyFunction
{
    public static class GetMetadataFromSB
    {
        static ISubscriptionClient subscriptionClient;
        [FunctionName("GetMetadataFromSB")]
        public static void Run([ServiceBusTrigger("TopicNameSB", "SubscriptionNameSB", Connection = "AzureServiceBusString")] string mySbMsg, ILogger log)
        {
            log.LogInformation($"C# ServiceBus topic trigger function processed message: {mySbMsg}");

        }
    }
}
Azure Service Bus
Azure Service Bus
An Azure service that provides cloud messaging as a service and hybrid integration.
700 questions
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. MayankBargali-MSFT 70,936 Reputation points Moderator
    2020-10-16T10:34:03.913+00:00

    Hi @Ankit Kumar

    The Function runtime receives a message in PeekLock mode. It calls Complete on the message if the function finishes successfully, or calls Abandon if the function fails. If the function runs longer than the PeekLock timeout, the lock is automatically renewed as long as the function is running. The same is mentioned in this document.

    Updated: As you have mentioned you can use autoComplete property to resolve the issue: https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus-output?tabs=csharp#hostjson-settings

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.