I am new azure functions. I have created an azure http trigger function in azure portal. I want to output message to a servicebus topic.
Here is my httptrigger function in the portal:
#load "..\sharedcode\DeleteCommandRequest.csx"
#r "Newtonsoft.Json"
#r "Microsoft.ServiceBus"
using System.Net;
using Newtonsoft.Json;
using Microsoft.ServiceBus
using Microsoft.ServiceBus.Messaging;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req,
TraceWriter log,
ServiceBus outputSbMsg)
{
log.Info("C# HTTP trigger function processed a request.");
DeleteCommandRequest request = await req.Content.ReadAsAsync<DeleteCommandRequest>();
log.Info($"Delete command recevied: {request.SagaId} {request.Action} {request.RequestId}");
var message = new BrokeredMessage(JsonConvert.SerializeObject(request));
outputSbMsg.send(message);
return request == null
? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass the correct request body")
: req.CreateResponse(HttpStatusCode.OK, "Hello " + JsonConvert.SerializeObject(request));
}
I am getting the following error:
error CS0246: The type or namespace name 'ServiceBus' could not be found (are you missing a using directive or an assembly reference?)
Can anyone please help how to output brokeredmessage to a servicebus topic from httptrigger?
I also tried from VS2017 precompiled azure function:
[FunctionName("DeleteCase")]
public static async Task<HttpResponseMessage> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)]
HttpRequestMessage req,
[ServiceBus("cqrs-commands", EntityType = EntityType.Topic)]
IAsyncCollector<BrokeredMessage> messageTopic,
TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
DeleteCommandRequest delRequest = await req.Content.ReadAsAsync<DeleteCommandRequest>();
log.Info($"Delete request received: {delRequest.SagaId} {delRequest.Action} {delRequest.RequestId}");
var brokeredMessage = new BrokeredMessage(delRequest);
await messageTopic.AddAsync(brokeredMessage);
return req.CreateResponse(HttpStatusCode.OK, JsonConvert.SerializeObject(delRequest));
}
But using the above code, the http trigger function not sending brokered message to the topic. Can anyone let me know what am i doing wrong here please?
Thanks