Paul Michaels
Paul Michaels

Reputation: 16705

Adding to a Queue using an Azure function in C#

I have the following function:

[FunctionName("Function1")]
public static HttpResponseMessage Run(
    [HttpTrigger(AuthorizationLevel.Function, "post")]HttpRequestMessage req,             
    TraceWriter log,
    [Queue("myqueuename")] ICollector<string> queue)
{
    . . .
    queue.Add(msg);

When I invoke this, I get no error, and the function appears to run correctly (I'm running it locally from VS atm). However, the queue in question doesn't get added to.

Looking around the web, I've seen at least one example that suggests using the BrokeredMessage class might work. I've tried using BrokeredMessage:

BrokeredMessage bm = new BrokeredMessage(new test() {test1 = msg});
queue.Add(bm);

This gives an error saying it can't read DeliveryCount.

This leaves me with two questions: firstly, should this work using ICollector<string> (and if so, what have I done wrong)? The second question relates to BrokeredMessage - it seems to exist in a Nuget package called ServiceBusv1_1 which has a description that makes me think it is not intended for this purpose: is that the correct package?

Upvotes: 0

Views: 636

Answers (1)

Mikhail Shilkov
Mikhail Shilkov

Reputation: 35144

Queue attribute means Azure Storage Queue, not Service Bus. Use ServiceBus attribute instead.

With that, both string and BrokeredMessage outputs should work fine.

You can walk through examples in docs.

Upvotes: 1

Related Questions