Larsi
Larsi

Reputation: 4774

Azure ApiApp - listen for ServiceBus msg

Say a have a CreateOrder method inside a ApiApp project.

Now I need to also trigger the CreateOrder when I receive a CreateOrderMessage from a ServiceBus queue.

I understand that this could be easily done using Azure Functions with a queue trigger. But that adds more complexity (introduces another concepts, will require a new repository, docs etc) So my question is simply:

Could I listen for queue messages inside of a WebApi project? (I know spinning up a new thread involves some problems)

Thanks for any suggestions

Larsi

Upvotes: 2

Views: 1459

Answers (2)

Tom Sun
Tom Sun

Reputation: 24569

We also could easily do that with azure function, we can import WebJob SDK to azure function using #r Microsoft.Azure.WebJobs, more detail info please refer azure functions C# developer reference. We can get the more info from reference how to create azure function.

We also can do that via WebJob, we also can easily deploy WebJob with VS. The following is the demo code:

public static void ProcessQueueMessage([ServiceBusTrigger("inputqueue")] string message, 
        TextWriter logger)

    {

         // Todo

    }

More details please refer to How to use Azure Service Bus with the WebJobs SDK.

Upvotes: 1

Slava Asipenko
Slava Asipenko

Reputation: 390

Technically, yes, you can. As you already mentioned, this is not a recommended approach, mainly due to possible complications in manual thread management, life cycle of your WebApi app, etc. Ideally message processing should be done in a web job, worker role, function, service, etc.

Upvotes: -1

Related Questions