Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I have an Async function that writes out to a service bus queue?

Using the Azure WebJobs SDK, I want to create an async function that will receive ServiceBus queue input and write to a ServiceBus queue output. Async methods cannot have out parameters which, for examples on BlobStorage, appears to be worked around by having Streams and TextWriters instead. However, when I try to do the same with a ServiceBus parameter I receive an exception.

public static async void Transform(
    [ServiceBusTrigger("%InputQueue%")] String input,
    [ServiceBus("%OutputQueue%")] TextWriter output,
    TextWriter log)

Error indexing method 'FilterCurrentCpesToNewCpes'

Can't bind ServiceBus to type 'System.IO.TextWriter'.

I receive a similar message for Stream.

like image 992
Micah Zoltu Avatar asked Oct 28 '14 06:10

Micah Zoltu


1 Answers

Since Async functions cannot have out parameters, you can bind to ICollector<T> or IAsyncCollector<T> and perform Add() operation to send a message. ICollector is defined in the WebJobs SDK.

Following sample demonstrates this.

 public static async void Transform(
[ServiceBusTrigger("%InputQueue%")] string input,
[ServiceBus("%OutputQueue%")] IAsyncCollector<string> output,
TextWriter log)
    {            
        await output.AddAsync(input);
    }
like image 61
pranav rastogi Avatar answered Oct 21 '22 09:10

pranav rastogi