2

我正在研究 azure IoT hubs 和连接技术工作,使用这里找到的教程: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').

我找不到导致这种情况的原因,因为我使用了一个基本示例,并且我的集线器似乎配置正确。顺便说一句,发送工作正常。有人有想法吗?

完整的错误日志:

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:
4

2 回答 2

2

您的问题来自您的企业代理。通过将 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>

希望能帮助到你

于 2017-04-05T12:33:39.590 回答
0

好吧,这很奇怪。这自己解决了。发布此消息后我回家了,并且测试发送和接收程序都运行良好。(是的,为了安全起见,我确实重新启动了它们)

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

如果有人遇到此问题并有明确的原因和解决方案,请务必将其作为答案。如果这可能再次发生,则可能需要它。

一个可能的原因是端口关闭或代理服务器不允许程序请求通过。我在家里试过了,没有代理,效果很好。因此,如果您遇到此问题,请在其他位置尝试。

于 2016-02-11T09:01:38.227 回答