Simple Example of Azure Function Chaining With Http Trigger and Queue Trigger

By Stephen Garside on 12/6/2017

using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;

 

namespace Serverless.Functions.PIM
{
 /// <summary>
 /// Simple Http Trigger
 /// </summary>
 public static class SimpleHttpTrigger
 {
  /// <summary>
  /// Fn Entry Point
  /// </summary>
  /// <param name="request">Http Request Message</param>
  /// <param name="log">Trace Writer</param>
  /// <param name="outputQueue">Output Queue</param>
  /// <returns>Http Status Code</returns>
  [FunctionName("SimpleHttpTrigger")]
 public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage request, TraceWriter log, [Queue("my-azure-storage-account-queue-name", Connection = "ServerlessStorageConnection")] IAsyncCollector<string> outputQueue)
  {
   await outputQueue.AddAsync("Queue Message String");

   return request.CreateResponse(HttpStatusCode.OK);
  }
 }
}

 

using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;

 

namespace Serverless.Functions.PIM
{
 /// <summary>
 /// Simple Queue Trigger
 /// </summary>
 public static class SimpleQueueTrigger
{
/// <summary>
/// Fn Entry Point
/// </summary>
/// <param name="queuedValue">Queued Value</param>
/// <param name="log">Trace Writer</param>
[FunctionName("SimpleQueueTrigger")]
public static void Run([QueueTrigger("my-azure-storage-account-queue-name", Connection = "ServerlessStorageConnection")] string queuedValue, TraceWriter log)
{
log.Info($"Function triggered and got this value from the queue : {queuedValue}");
}
}
}

{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "someaccountname",
"AzureWebJobsDashboard": "",
"ServerlessStorageConnection": "DefaultEndpointsProtocol=https;AccountName=someaccountname;AccountKey=someaccountkey;EndpointSuffix=core.windows.net"
}

Share this article...
Join the Discussion...