13

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.

Micah Zoltu
  • 6,764
  • 5
  • 44
  • 72

1 Answers1

20

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);
    }
pranav rastogi
  • 4,124
  • 23
  • 23