-5

I understand that Azure Service Bus is a messaging system. But what I don't understand is how this fits into a CRUD app scenario. Lets say I have a Person class that has some properties/getter/setter methods. And when a user wants to create a new person the "program" will create a new person object and add it to the queue. How will the "back-end" code look. It has to pick up this request and add it to a database but how does it now this?

user8132396
  • 131
  • 1
  • 1
  • 5
  • It knows this because you told it that's how it works :) You add a message on a queue, the back-end picks up the message and processes it. There's several ways you could go about this: You could have multiple queues for multiple types of actions, a message could contain the action it's supposed to trigger, you could use an id of -1 (or any other db-invalid value) to indicate you want to add the entity... There are so many options. – rickvdbosch Jul 19 '17 at 07:55
  • Plus, the message you add to the queue can be serialized data. I've used JSON string in the past so they are also human readable. The "worker" that "listens" for messages on that queue, will deserialize that object and do the specific job it's designed for. – reckface Jul 19 '17 at 07:59

1 Answers1

1

How will the "back-end" code look. It has to pick up this request and add it to a database but how does it now this?

You could create a WebJob or Azure Function to handle the queue message when a new message is added to the queue. Then you could deserialize the object from the message and add it to database.

A Service Bus Queue trigger is like this.

public class Functions
{
    public static void ProcessQueueMessage([ServiceBusTrigger("inputqueue")] string message, TextWriter logger)
    {
        //deserialize the object from the message and add it to database.
    }
}

For more information, link below is for your reference.

How to use Azure Service Bus with the WebJobs SDK

Amor
  • 8,325
  • 2
  • 19
  • 21