使用服务总线触发器在 Azure Function 中自动转发消息

Auto forward message in Azure Function with Service Bus trigger

当我有一个自动转发队列时,Azure 函数无法启动:

函数 XXX 错误:函数 'FunctionXXX' 的侦听器无法启动。 Microsoft.ServiceBus: 无法在启用了自动转发的实体上创建消息接收器。

            // Code to create the queue:
            var manager = NamespaceManager.CreateFromConnectionString("ConnectionString");
            manager.CreateQueue(new QueueDescription("myqueue_done")
            {
                RequiresSession = false
            });
            manager.CreateQueue(new QueueDescription("myqueue")
            {
                ForwardTo = "myqueue_done",
                RequiresSession = false
            });

这是我的 azure 函数:

    [FunctionName("FunctionXXX")]
    public static void Run([ServiceBusTrigger("myqueue", Connection = "AzureSbConnectionString")]string myQueueItem, string messageId, string CorrelationId, TraceWriter log)
    {          

        log.Info($"Message id={messageId}, CorrelationId={CorrelationId}, was processed: {myQueueItem}");
    }

真的有限制吗?有没有更好的方法在这个 azure 函数沙箱方法中移动已处理的消息?

谢谢!

这不是函数的限制,而是服务总线的工作方式。

When auto-forwarding is enabled, Service Bus automatically removes messages that are placed in the first queue or subscription (source) and puts them in the second queue or topic (destination).

如果您的消息被转发到另一个队列并从原始队列中删除,那么从同一队列创建手动接收方就没有实际意义。