-2

Is it possible to run an Azure Function app that has no function, but running threads that will read messages from Azure Service Bus?

It seems the thread is not reading mesasge from ASB.

Update

My Function app (has no functions) works locally, but not on Azure.

Pingpong
  • 7,681
  • 21
  • 83
  • 209

2 Answers2

3

Azure Functions are marketed as

More than just event-driven serverless compute

The event-driven part is key here. The actual Function in a Function app is the code that's triggered by for instance a timer, a message on a Service Bus or an Event Grid event. All other code should be supporting in getting that job done. If you have a Functions App that doesn't have any functions, you don't have any entry point for your code to run.

Two main remarks:

  1. It kinda feels like you're trying to abuse Functions
  2. Why not use Service Bus triggers instead of a thread doing the same thing manually?

Have a look at this example, taken from Azure Service Bus bindings for Azure Functions - Trigger - C# example:

[FunctionName("ServiceBusQueueTriggerCSharp")]                    
public static void Run(
    [ServiceBusTrigger("myqueue", AccessRights.Manage, Connection = "ServiceBusConnection")] 
    string myQueueItem,
    Int32 deliveryCount,
    DateTime enqueuedTimeUtc,
    string messageId,
    ILogger log)
{
    log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
    log.LogInformation($"EnqueuedTimeUtc={enqueuedTimeUtc}");
    log.LogInformation($"DeliveryCount={deliveryCount}");
    log.LogInformation($"MessageId={messageId}");
}

This example shows a C# function that reads message metadata and logs a Service Bus queue message.

rickvdbosch
  • 14,105
  • 2
  • 40
  • 53
  • I was looking for why it is not working. SO only allows one answer, I wish I could assign this great comment as answer as well. – Pingpong Jun 04 '19 at 00:07
1

The likely reason your Function application works locally but not in Azure is due to how the Consumption plan works. The function application will not be running until infrastructure in Azure detects that one of our official supported triggers indicates that your function application needs to start. Only at that point will an instance of your application be created. This is how we enable our cheap pricing, because your code is only running when it is needed.

As others have stated in the comments and to add to rickvdbosch's excellent answer, a Azure Functions application without any actual Azure Functions running on it doesn't make much sense. You are not using any of the features of Azure Functions without having any code running in an Azure Function. If you really want to implement a background thread running at all times, a dedicated Azure Web App would be the correct approach.

With that said, using Service Bus triggers as recommended by rickvdbosch would handle much of the boilerplate you likely had to write inside of your background thread, as well as enable you to use the Azure Functions Consumption Plan, with all of the pricing benefits that those bring.

Connor McMahon
  • 1,318
  • 7
  • 15