Azure IoT hub basic receiving example, AMQP error

2019-07-14 02:46发布

I'm delving into azure Iot hubs and connected technologie for work, using the tutorial found here: https://azure.microsoft.com/nl-nl/documentation/articles/iot-hub-csharp-csharp-getstarted/

When running the receiver example (this section of the article: https://azure.microsoft.com/nl-nl/documentation/articles/iot-hub-csharp-csharp-getstarted/#receive-device-to-cloud-messages)

I get an error on the line:

var d2cPartitions = eventHubClient.GetRuntimeInformation().PartitionIds;

I get this error (complete error log at the bottom):

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

I cannot find what causes this, since I use a basic example, and my hub appears rightly configured. Sending works fine btw. Anyone got an idea?

Complete error log:

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条回答
劳资没心,怎么记你
2楼-- · 2019-07-14 03:27

Your issue comes from your enterprise proxy. You can easily define a proxy to EventHubClient by setting the Service Bus environnement communication mode to HTTP. In your c# add this :

ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Http;

then in your app.config file add :

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

Hope it helps

查看更多
混吃等死
3楼-- · 2019-07-14 03:27

Ok, this is weird. This solved itself. I left for home after posting this, and testing both the sending and receiving program worked fine. (Yes I did restart them just to be safe)

Cause? No idea. Perhaps the daily cleanup of the hub solved it, but it's still weird.

If anyone comes across this problem and has a clear cause and solution, do put it up as an answer. If this may happen again it might be needed.

A probable cause is is either a closed port or a proxy server not letting the programs request through. I tried it at home, without proxy, and it worked fine. So if you experience this problem, try it at another location.

查看更多
登录 后发表回答