首页 文章

Azure IoT hub基本接收示例,AMQP错误

提问于
浏览
2

我正在深入研究azure Iot集线器和连接技术的工作,使用此处的教程:https://azure.microsoft.com/nl-nl/documentation/articles/iot-hub-csharp-csharp-getstarted/

运行接收器示例时(本文的这一部分:https://azure.microsoft.com/nl-nl/documentation/articles/iot-hub-csharp-csharp-getstarted/#receive-device-to-cloud-messages

我收到错误:

var d2cPartitions = eventHubClient.GetRuntimeInformation().PartitionIds;

我收到此错误(底部的完整错误日志):

Message=An AMQP error occurred (condition='amqp:link:redirect').

我无法找到导致这种情况的原因,因为我使用了一个基本示例,并且我的集线器显示正确配置 . 发送工作很好btw . 有人有个主意吗?

完整的错误日志:

Microsoft.ServiceBus.Messaging.MessagingException was unhandled
  HResult=-2146233088
  IsTransient=true
  Message=An AMQP error occurred (condition='amqp:link:redirect').
  Source=Microsoft.ServiceBus
  StackTrace:
Server stack trace: 
Exception rethrown at [0]: 
   at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at Microsoft.ServiceBus.Messaging.AmqpClient.AmqpManagementLink.EndCreateManagementLink(IAsyncResult result)
   at Microsoft.ServiceBus.Messaging.Amqp.FaultTolerantObject`1.CreateAsyncResult.<GetAsyncSteps>b__4(CreateAsyncResult thisPtr, IAsyncResult r)
   at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult result)
Exception rethrown at [1]: 
   at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at Microsoft.ServiceBus.Common.AsyncResult`1.End(IAsyncResult asyncResult)
   at Microsoft.ServiceBus.Messaging.Amqp.FaultTolerantObject`1.OnEndCreateInstance(IAsyncResult asyncResult)
   at Microsoft.ServiceBus.Messaging.SingletonManager`1.EndGetInstance(IAsyncResult asyncResult)
   at Microsoft.ServiceBus.Messaging.AmqpClient.AmqpManagementLink.AmqpManagementOperationAsyncResult`1.<GetAsyncSteps>b__21(T thisPtr, IAsyncResult r)
   at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult result)
Exception rethrown at [2]: 
   at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at Microsoft.ServiceBus.Messaging.Amqp.AmqpEventHubClient.GetRuntimeInfoAsyncResult.<GetAsyncSteps>b__18(GetRuntimeInfoAsyncResult thisPtr, IAsyncResult r)
   at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult result)
Exception rethrown at [3]: 
   at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.RunSynchronously()
   at Microsoft.ServiceBus.Messaging.Amqp.AmqpEventHubClient.GetRuntimeInformation()
   at ReadDeviceToCloudMessages.Program.Main(String[] args) in C:\Users\tmartena\documents\visual studio 2015\Projects\azureTestDevice\ReadDeviceToCloudMessages\Program.cs:line 21
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
InnerException:

2 回答

  • 0

    您的问题来自您的企业代理 . 您可以通过将Service Bus环境通信模式设置为HTTP,轻松地为EventHubClient定义代理 . 在你的c#中添加:

    ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Http;
    

    然后在你的app.config文件中添加:

    <system.net>
        <defaultProxy>
          <proxy bypassonlocal="True" proxyaddress="http://proxyadress:port" />
        </defaultProxy>
      </system.net>
    

    希望能帮助到你

  • 1

    好的,这很奇怪 . 这解决了自己 . 发布后我离开回家,测试发送和接收程序工作正常 . (是的,为了安全,我确实重启了它们)

    原因?不知道 . 也许集线器的每日清理解决了它,但它仍然很奇怪 .

    如果有人遇到这个问题并且有明确的原因和解决方案,那么请把它作为答案 . 如果这可能再次发生,则可能需要它 .

    可能的原因是关闭端口或代理服务器不让程序请求通过 . 我在家里尝试了它,没有代理,它工作得很好 . 因此,如果您遇到此问题,请在其他位置尝试 .

相关问题