简体   繁体   English

Azure Function 事件中心 Output 绑定在部署时不起作用

[英]Azure Function Event Hub Output Binding not working when deployed

I am using an Azure Function to get messages from a Rabbit MQ Broker to an Event Hub.我正在使用 Azure Function 将消息从 Rabbit MQ 代理获取到事件中心。

The function works perfect when I run it locally.当我在本地运行 function 时,它可以完美运行。

Here is the code of the function:这是function的代码:

using System.Text;
using System.Dynamic;
using System.Threading.Tasks;
using CaseOnline.Azure.WebJobs.Extensions.Mqtt;
using CaseOnline.Azure.WebJobs.Extensions.Mqtt.Messaging;
using Microsoft.Azure.WebJobs;
using Newtonsoft.Json;
 
public static class Test
{
 
    [FunctionName("EventHubOutput")]
 
    public static async Task Run(
        [MqttTrigger("topic/#")] IMqttMessage message,
        [EventHub("eventhubname", Connection = "EventHubConnectionAppSetting")] IAsyncCollector<string> outputEvents,
        ILogger log)
    {
        var body = message.GetMessage();
        var bodyString = Encoding.UTF8.GetString(body);
        dynamic obj = JsonConvert.DeserializeObject<ExpandoObject>(bodyString);
        obj.Topic = message.Topic;
 
        await outputEvents.AddAsync(JsonConvert.SerializeObject(obj));
    }
}

When deployed and run in the Azure portal, I get the following error messages:在 Azure 门户中部署和运行时,我收到以下错误消息:

Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: EventHubOutput
---> System.InvalidOperationException: Error while handling parameter outputEvents after function returned:
---> System.Net.Sockets.SocketException (0xFFFDFFFF): Name or service not known
at (...)

Any idea what the problem might be?知道问题可能是什么吗?

Thank you.谢谢你。

You are using the bindings incorrectly.您使用的绑定不正确。 Check out RabbitMQ bindings for Azure Functions overview .查看Azure 函数概述的 RabbitMQ 绑定

The following example shows a C# function that reads and logs the RabbitMQ message as a RabbitMQ Event:以下示例显示了一个 C# function 读取 RabbitMQ 消息并将其记录为 Z7EAA993723E57B2E17Z 消息作为事件:

[FunctionName("RabbitMQTriggerCSharp")]
public static void RabbitMQTrigger_BasicDeliverEventArgs(
    [RabbitMQTrigger("queue", ConnectionStringSetting = "rabbitMQConnectionAppSetting")] BasicDeliverEventArgs args,
    ILogger logger
    )
{
    logger.LogInformation($"C# RabbitMQ queue trigger function processed message: {Encoding.UTF8.GetString(args.Body)}");
}

The following example shows how to read the message as a POCO:以下示例显示了如何将消息作为 POCO 读取:

namespace Company.Function
{
    public class TestClass
    {
        public string x { get; set; }
    }

    public class RabbitMQTriggerCSharp{
        [FunctionName("RabbitMQTriggerCSharp")]
        public static void RabbitMQTrigger_BasicDeliverEventArgs(
            [RabbitMQTrigger("queue", ConnectionStringSetting = "rabbitMQConnectionAppSetting")] TestClass pocObj,
            ILogger logger
            )
        {
            logger.LogInformation($"C# RabbitMQ queue trigger function processed message: {pocObj}");
        }
    }
}

I recommend you to check out this complete guide to setup Rabbit MQ Trigger in Azure Functions: RabbitMQ trigger for Azure Functions overview我建议您查看此完整指南以在 Azure 函数中设置 Rabbit MQ 触发器: RabbitMQ 触发器用于 Azure 函数概述

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

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