-
Notifications
You must be signed in to change notification settings - Fork 0
/
PopulateSourceQueue.cs
46 lines (41 loc) · 1.68 KB
/
PopulateSourceQueue.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Microsoft.Azure.Storage.Queue;
namespace Olakusibe.AzureFunctions.RequeueItems
{
public static class PopulateSourceQueue
{
[FunctionName(nameof(PopulateSourceQueue))]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
IBinder binder,
ILogger log)
{
log.LogInformation($"C# HTTP trigger function {nameof(PopulateSourceQueue)} processed a request.");
try
{
// put messages on the queue (enqueue operation)
var queueAttr = new QueueAttribute(RequeueSampleData.sourceQueueName);
var cloudQueue = await binder.BindAsync<CloudQueue>(queueAttr);
var queueMessage = new CloudQueueMessage(RequeueSampleData.messageOnQueue);
int numberOfMessagesToEnqueue = 42;
for (int i = 0; i < numberOfMessagesToEnqueue; i++)
{
await cloudQueue.AddMessageAsync(queueMessage);
}
return new OkObjectResult($"{numberOfMessagesToEnqueue:N0} messages were enqueued for processing.");
}
catch (Exception ex)
{
return new BadRequestObjectResult($"Error Messgae: {ex.Message}");
}
}
}
}