6

I'm developing ASP.NET Web API services and placing these onto an Azure Service Bus queue to be processed. The Web API services are hosted on Azure.

I need to implement an application that listens for these messages and processes them when they are received.

I'd like this to be hosted on Azure but not sure of the best way to approach this.

  • Can you implement such a listener service and host it on Azure?
  • What is the best way to approach implementing such an application / service?
DomBurf
  • 2,452
  • 5
  • 36
  • 71

3 Answers3

8

There are several things you can do. You could use ASB's OnMessage API which allows you to register your callback and handle incoming messages with concurrency and auto-completion.

On Azure you have several options: Cloud Services (worker roles), Azure Web Jobs, Azure Functions (if your processing is fast, otherwise I'd not recommend it), Service Fabric (might be a bit of an overkill if system is small), and plain VMs if needs to be.

Warning about functions - if you do intense work, Functions are not ideal as you'll pay for time/memory you execute.

Sean Feldman
  • 23,443
  • 7
  • 55
  • 80
  • @juunas beat me to it :) Clarification though - web jobs don't have a problem to run longer than 5-10 minutes. If hosted under the plan that has always-on, you're paying for the hosting plan anyways. So might use it as well. With functions, personal opinion, if you run more than a few seconds, you're doing something incorrect. Functions should be blazing fast. 5 mins would not qualify. – Sean Feldman Dec 21 '16 at 18:54
  • I though the ASB OnMessage API would come in somewhere but wasn't sure quite where it fitted into the jigsaw. puzzle. Our needs are fairly small so hopefully either option should be workable. I'll need to spend some time looking into these options and decide which is the better fit. – DomBurf Dec 22 '16 at 09:03
  • @SeanFeldman True, you can run longer web jobs, but you may run into some timeout limits (which can be adjusted). – juunas Dec 22 '16 at 09:10
  • Just to clarify, would you implement OnMessage in your Azure Function or Web Job? Or is this used for on-premise applications? For smaller requirements what is the preferred option between Function and Web Job? When would you typically use an Azure Function over an Azure Web Job? – DomBurf Dec 22 '16 at 11:59
  • Functions and webjobs can be triggered by ASB messages w/o need to have a message pump. Webjobs, when executed as continuous, could use OnMessage API. Cloud services and Service fabric options do not have the concept of triggers and would require a message pump to receive messages. – Sean Feldman Dec 22 '16 at 14:42
2

A couple options for workers that listen to a queue are:

  1. Functions
  2. Web Jobs

You can see an example of using a Function here: https://learn.microsoft.com/en-us/azure/azure-functions/functions-create-an-event-processing-function.

An example of using Web Jobs is here: https://learn.microsoft.com/en-us/azure/app-service-web/websites-dotnet-webjobs-sdk-service-bus.

Both allow you to create background jobs that consume messages from a queue. Both support Storage and Service Bus queues. The main difference is that Web Jobs require an App Service Plan with some amount of instances, while Functions can run on a Dynamic plan, which scales completely automatically.

You should note that Functions are not meant for really long-running jobs (more than 5-15 minutes), though neither are Web Jobs.

juunas
  • 54,244
  • 13
  • 113
  • 149
0

Why not trying to run a linux process (daemon) in docker.

Dorin
  • 524
  • 3
  • 12
  • 1
    This suggestion isn't such a bad one at all. i.e. Compile your ServiceBus listener into a .net core console app (with or without web jobs) and run it on a docker container. – StuartLC Aug 15 '18 at 05:38