Migrating Azure Function with Service Bus Trigger to Azure Kubernetes Job Failing

devopsfj 256 Reputation points
2022-08-24T15:13:46.837+00:00

Good Afternoon,

I am migrating a .NET Function App which has a Service Bus Trigger, the Function currently runs on a App Service Plan.

I am using KEDA which is working fine, it triggers a Job whenever there is a message in the Service Bus Queue.

The issue we are having is that the job is being reported as failed, even though the function is doing what we expect, the function takes messages from the queue and posts them to an API, this works fine, so the function itself is working OK, it just looks like the function never exits, which causes the job to timeout and be marked as failed.

After investigation it appears as though it is because of the function having a Service Bus Listener which continues to listen for more messages in the queue after it has processed one.

These logs appear on the Pod once Kubernetes has started to terminate the pod, so it looks like the listener is not being stopped after processing the message on the queue:

   info: Host.Startup[0]  
         Stopped the listener 'Microsoft.Azure.WebJobs.ServiceBus.Listeners.ServiceBusListener' for function 'MyFunction'  
   info: Microsoft.Azure.WebJobs.Host.DrainModeManager[0]  
         Call to StopAsync complete, registered listeners are now stopped  

How can we stop this behaviour, we do not want the Function to continue to listen for more messages after it has processed the message on the queue, this is not the behaviour we are seeing on the function app.

Thanks

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
Azure Kubernetes Service
Azure Kubernetes Service
An Azure service that provides serverless Kubernetes, an integrated continuous integration and continuous delivery experience, and enterprise-grade security and governance.
2,447 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MughundhanRaveendran-MSFT 12,506 Reputation points
    2022-08-30T07:25:16.367+00:00

    Hi @devopsfj ,

    Thanks for posting this query in Q&A forum.

    The below message would be mostly seen when the host is shutting down. In your scenario, you are seeing this message when the pod is getting terminated, so this message is expected from the function host.

    Stopped the listener 'Microsoft.Azure.WebJobs.ServiceBus.Listeners.ServiceBusListener' for function 'MyFunction'

    Please note that, this message does not indicate that the host is still listening to the service bus queue.

    However, I am curious to know about this behavior "The issue we are having is that the job is being reported as failed, even though the function is doing what we expect". Please share the error message that you get so that I can provide my insights.


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.