Reputation: 167
I'm using the service bus with an azure function. The function is triggered by a queue, then the ReplyTo property on the input BrokeredMessage is to be used as the queue to respond on. How can I dynamically bind to the output queue? I've tried the code below, but get:
Can't bind ServiceBus to type 'Microsoft.ServiceBus.Messaging.BrokeredMessage'.
public static async Task Run(BrokeredMessage msg, Binder binder, TraceWriter log)
{
log.Info($"C# ServiceBus queue trigger function processed message");
var msgout = await binder.BindAsync<BrokeredMessage>(new ServiceBusAttribute(msg.ReplyTo));
}
function.json
{
"disabled": false,
"bindings": [
{
"name": "msg",
"type": "serviceBusTrigger",
"direction": "in",
"queueName": "myInputQueue",
"connection": "AzureWebJobsServiceBus",
"accessRights": "Manage"
}
]
}
Upvotes: 3
Views: 2506
Reputation: 13558
For output scenarios, you need to bind to type IAsyncCollector:
public static async Task Run(
BrokeredMessage msg, Binder binder, TraceWriter log)
{
log.Info($"C# ServiceBus queue trigger function processed message");
var collector = await binder.BindAsync<IAsyncCollector<BrokeredMessage>>(
new ServiceBusAttribute(msg.ReplyTo));
var message = ...
await collector.AddAsync(message);
}
Upvotes: 3