azure - IOT 中心消息处理器

标签 azure iot azure-iot-hub

处理在 Azure IoT 中心创建的消息时遇到一些问题。

出现以下错误:抛出异常:Microsoft.ServiceBus.dll 中的“Microsoft.ServiceBus.Messaging.Amqp.AmqpException”(“发生 AMQP 错误(条件='amqp:link:redirect')。”)

有人能指出我正确的方向吗?

问候, 乔纳斯

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.ServiceBus.Messaging;

namespace IOTHubMessageProcessor
{
    class Program
    {
        static string connectionString = "HostName=yaddaaaa.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=keydataasdss+tacsCxwkWQeUm9sMCc2GHnQkIZHM=";
        static string iotHubD2cEndpoint = "messages/events";
        static EventHubClient eventHubClient;
        static void Main(string[] args)
        {

            Console.WriteLine("Receive messages\n");
            eventHubClient = EventHubClient.CreateFromConnectionString(connectionString, iotHubD2cEndpoint);

            var d2cPartitions = eventHubClient.GetRuntimeInformation().PartitionIds;

            foreach (string partition in d2cPartitions)
            {
                ReceiveMessagesFromDeviceAsync(partition);
            }
            Console.ReadLine();
        }


        private async static Task ReceiveMessagesFromDeviceAsync(string partition)
        {
            var eventHubReceiver = eventHubClient.GetDefaultConsumerGroup().CreateReceiver(partition, DateTime.UtcNow);

            while (true)
            {
                EventData eventData = await eventHubReceiver.ReceiveAsync();
                if (eventData == null) continue;

                string data = Encoding.UTF8.GetString(eventData.GetBytes());
                Console.WriteLine(string.Format("Message received. Partition: {0} Data: '{1}'", partition, data));
            }
        }
    }
}

最佳答案

我在使用您的代码进行测试时没有遇到此问题,因此它可能与其他问题有关。我找到重复的线程 Azure IoT hub basic receiving example, AMQP error ,建议检查阻止端口或代理设置,你可以尝试一下。

关于azure - IOT 中心消息处理器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35725763/

相关文章:

c# - 调用 Sub Orchestrator 时无需等待 - Azure Durable Functions

azure - 与 Auzure 物联网集线器的设备连接(在线/离线)状态

azure - 如何在 Microsoft Azure IoT 中创建流数据的自定义仪表板?

java - 与 "azure-iot-sdk-java"; DeviceClient 实例的预期生命周期是多少

Azure IoT Edge 设置成功完成,但未启动 EdgeAgent docker 镜像

azure - 如果我的客户端 key 过期,我可以重新生成访问 token 和刷新 token 对吗?

azure - Get-MsolUserRole Azure AD V2 cmdlet 等效项

python - 使用 Raspberry Pi 和 Bluemix 的 IoT Python 应用程序 : Pushing the button doesn't work

python - 使用适用于 Python 的 Azure IoT SDK 上传图像

asp.net - Azure 获取 API 响应时间