Writing to queues, blobs and databases with output bindings
Output bindings let a function write to another service just by returning a value: put a message on a queue, write a blob, send to Service Bus or save a Cosmos DB document, without writing client code.
- StartHTTP POST arrivesThe trigger binds the JSON body.
- Step 2Function saves orderYour code returns the output object.
- Step 3HTTP result202 Accepted goes back to the caller.
- EndQueue outputOrderPlaced is written to the orders queue.
The runtime writes every output after the method returns.
One output: return it
In the isolated model you put the output attribute on the method and return the value.
[Function("ResizeRequested")]
[QueueOutput("resize-jobs", Connection = "Storage")]
public ResizeJob Run([BlobTrigger("uploads/{name}", Connection = "Storage")] string name)
=> new ResizeJob(name, Width: 320);Several outputs: return a class
To send an HTTP response and a queue message, return a type whose properties carry the bindings. With ASP.NET Core integration, mark the HTTP result with [HttpResult].
public class CreateOrderOutput
{
[HttpResult] public IActionResult Response { get; set; } = default!;
[QueueOutput("orders", Connection = "Storage")]
public OrderPlaced? Message { get; set; }
}
[Function("CreateOrder")]
public async Task<CreateOrderOutput> Run(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = "orders")] HttpRequest req,
[FromBody] NewOrder input)
{
int id = await _store.AddAsync(input);
return new CreateOrderOutput
{
Response = new AcceptedResult($"/api/orders/{id}", new { id }),
Message = new OrderPlaced(id, input.Email),
};
}Bindings or SDK clients?
- Use output bindings for the simple cases: one message, one blob, one document.
- Return an array to write several queue messages at once.
- Inject SDK clients (ServiceBusClient, BlobContainerClient, CosmosClient) when you need full control: message properties, conditional writes, transactions or reading and writing in one step.
- Outputs are written after the function returns; if writing fails, the invocation fails.
Interview question
How do you return an HTTP response and also write a queue message from one isolated worker function?
I return a custom output class. One property holds the HTTP response and is marked [HttpResult] when using ASP.NET Core integration, and another property is marked [QueueOutput] with the queue name and connection. The runtime sends the response and writes the message after the method returns.
Want the full details? Read the official Microsoft documentation for this topic.