I am trying to output the body of a JSON http POST to Azure Service Bus.
The Azure documentation provides an example but this is a time based function trigger, not an HTTP trigger.
https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus#output
Here is my run.csx
#r "Newtonsoft.Json"
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
public static async Task<IActionResult> Run(HttpRequest req)
{
// req is the object passed into function
// read in the whole body, await as it reads to the end to get all?
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
// deserialize the request body from JSON to a dynamic object called data
dynamic data = JsonConvert.DeserializeObject(requestBody);
// ok so now we have our request body in JSON in the data variable.
// we need to put it on the service bus somehow
string message = $"Service Bus queue message created at: {DateTime.Now}";
outputSbQueue = message;
return (ActionResult)new OkObjectResult("Ok");
}
And my function.json file:
{
"bindings": [
{
"authLevel": "function",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"methods": [
"get",
"post"
]
},
{
"name": "$return",
"type": "http",
"direction": "out"
},
{
"type": "serviceBus",
"connection": "message-bus_CONNECT",
"name": "outputSbQueue",
"queueName": "test",
"direction": "out"
}
]
}
Any guidance is appreciated. I am a newb. This is purely for testing.
UPDATE 5/28/19
This is working:
#r "Newtonsoft.Json"
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using System.Net.Http;
public static void Run(HttpRequest req, out string outputSbQueue)
{
// Working as of 5.28.2019 10:48 PM
StreamReader reader = new StreamReader( req.Body );
string text = reader.ReadToEnd();
outputSbQueue = text;
}
However I have no logic to return a status to the caller.