How to do it...

Perform the following steps:

  1. Using the Azure Storage Explorer, create a queue named registeruserqueue in the storage account named azurefunctionscookbook. We assume that all the other applications would be creating messages in the registeruserqueue queue.
  2. Navigate to Azure Functions and create a new Azure Function using Azure Queue Storage trigger, then choose the queue that we have created.
  3. You might be prompted to install storage extensions if not installed already. Once you install the extensions, provide the details of the queue and click on the Create button, as shown in the following screenshot:
  1. Once the function is created, replace the default code with the following code. Whenever a queue message is created, the JSON message will be deserialized automatically and populated in an object named myQueueItem. In the following code, we are just printing the values of the objects in the Logs window:
using System;
public static void Run(User myQueueItem, ILogger log)
{

log.LogInformation($"A Message has been created for a new User");
log.LogInformation($"First name: {myQueueItem.firstname}" );
log.LogInformation($"Last name: {myQueueItem.lastname}" );
log.LogInformation($"email: {myQueueItem.email}" );
log.LogInformation($"Profile Url: {myQueueItem.ProfilePicUrl}" );
}
public class User
{
public string firstname { get;set;}
public string lastname { get;set;}
public string email { get;set;}
public string ProfilePicUrl { get;set;}
}
  1. Navigate to Azure Storage Explorer and create a new message in registeruserqueue, as shown in the following screenshot:
  1. Click on OK to create the queue message and navigate back to the Azure Function and look at the logs, as shown in the following screenshot: