处理在 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/