简体   繁体   English

使用C#中的Azure函数添加到队列

[英]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). 当我调用它时,我没有收到任何错误,并且该函数似乎正常运行(我是从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. 环顾网络,我至少看到一个建议使用BrokeredMessage类的示例。 I've tried using BrokeredMessage : 我试过使用BrokeredMessage

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

This gives an error saying it can't read DeliveryCount . 这给出了一个错误,表明它无法读取DeliveryCount

This leaves me with two questions: firstly, should this work using ICollector<string> (and if so, what have I done wrong)? 这给我留下了两个问题:首先,是否应该使用ICollector<string>这项工作(如果是,那我做错了什么)? 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? 第二个问题与BrokeredMessage -它似乎存在于名为ServiceBusv1_1的Nuget程序包中,该程序包中的描述使我认为不打算用于此目的:这是正确的程序包吗?

Queue attribute means Azure Storage Queue, not Service Bus. Queue属性表示Azure存储队列,而不是服务总线。 Use ServiceBus attribute instead. 请改用ServiceBus属性。

With that, both string and BrokeredMessage outputs should work fine. 这样, stringBrokeredMessage输出都应该可以正常工作。

You can walk through examples in docs . 您可以浏览docs中的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM