0

I have an azure function like this:

[FunctionName("DoStuff")]
[return: Queue("stuff-queue")]
public static async Task<StuffContext> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log)
{
    var context = await req.Content.ReadAsAsync<StuffContext>();
    context.TransactionId = Guid.NewGuid();
    return context;
}

It listens on a https url, deserializes the request body, and send body to the queue. Can I also have it return something (the transaction id in this case) as part of the http response.

Joy Wang
  • 39,905
  • 3
  • 30
  • 54
Justin Dearing
  • 14,270
  • 22
  • 88
  • 161

1 Answers1

0

Can I also have it return something (the transaction id in this case) as part of the http response.

Using [return: Queue("stuff-queue")] will return the information to the queue. But it could not return a response and add the information to the queue at the same time.

If you want to do, you could refer to my code.It works fine on my side.

public static async Task<HttpResponseMessage> Run(
        [HttpTrigger(AuthorizationLevel.Function, "get", "post")]HttpRequestMessage req,
        TraceWriter log,
        [Queue("stuff-queue")] IAsyncCollector<string> outputQueue)
        {
            log.Info("C# HTTP trigger function processed a request.");
            string yourinfo = "yourinfo";       
            await outputQueue.AddAsync(yourinfo);
            return req.CreateResponse(HttpStatusCode.OK, yourinfo);

        }

For more details, you could refer to this article.

Joy Wang
  • 39,905
  • 3
  • 30
  • 54