You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Event Hub报错“No such host is known”问题排查求助

关于Azure Event Hub连接错误"No such host is known"的排查与解决

问题背景

我订阅了Azure Event Hub以获取消息,使用的C#代码如下:

BlobContainerClient storageClient = new BlobContainerClient(new Uri(serviceConfig.BlobContainerName), certificate);

var processor = new EventProcessorClient
(
    storageClient,
    EventHubConsumerClient.DefaultConsumerGroupName,
    eventHubNamespace,
    eventHubName,
    certificate
);

processor.ProcessEventAsync += ProcessEventHandler;
processor.ProcessErrorAsync += ProcessErrorHandler;

await processor.StartProcessingAsync();

错误详情

运行代码时触发错误,核心异常信息:

eventArgs.Exception.Message: No such host is known

错误发生在操作:Retrieving list of partition identifiers from a Consumer Client

完整堆栈跟踪:

[EventHubListener] error StackTrace    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Azure.Amqp.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at Microsoft.Azure.Amqp.Transport.AmqpTransportInitiator.<>c.<ConnectAsync>b__17_1(IAsyncResult r)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Azure.Messaging.EventHubs.Amqp.AmqpConnectionScope.<CreateAndOpenConnectionAsync>d__80.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Amqp.FaultTolerantAmqpObject`1.<OnCreateAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Azure.Amqp.Singleton`1.<GetOrCreateAsync>d__24.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Azure.Amqp.Singleton`1.<GetOrCreateAsync>d__24.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Azure.Messaging.EventHubs.Amqp.AmqpConnectionScope.<OpenManagementLinkAsync>d__76.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Amqp.FaultTolerantAmqpObject`1.<OnCreateAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Azure.Amqp.Singleton`1.<GetOrCreateAsync>d__24.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Azure.Amqp.Singleton`1.<GetOrCreateAsync>d__24.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Azure.Messaging.EventHubs.Amqp.AmqpClient.<GetPropertiesAsync>d__30.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Azure.Messaging.EventHubs.Amqp.AmqpClient.<GetPropertiesAsync>d__30.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Azure.Messaging.EventHubs.EventHubConnection.<GetPropertiesAsync>d__37.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Azure.Messaging.EventHubs.EventHubConnection.<GetPartitionIdsAsync>d__38.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Azure.Messaging.EventHubs.Primitives.EventProcessor`1.<ListPartitionIdsAsync>d__83.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Azure.Messaging.EventHubs.Primitives.EventProcessor`1.<RunProcessingAsync>d__87.MoveNext()

已执行的测试

在部署代码的机器上运行了网络连通性测试命令:

.\psping.exe -n 25 -i 1 -q .servicebus.windows.net:5671 -nobanner

测试结果显示所有请求均超时。

身份验证说明:使用分配了Event Hub Owner/Reader/Writer角色的服务主体,通过证书进行身份验证。

排查与解决建议

  • 核对Event Hub命名空间地址:确认eventHubNamespace变量的值格式为{你的命名空间}.servicebus.windows.net,检查是否存在拼写错误、前缀缺失或格式错误,这是DNS解析失败的最常见原因。
  • 验证DNS解析能力:
    • 在部署机器上执行nslookup {你的命名空间}.servicebus.windows.net,确认能正常解析到Azure的IP地址。若解析失败,检查机器DNS服务器配置,尝试切换到公共DNS(如8.8.8.8)测试。
    • 企业内网环境下,确认防火墙或代理是否拦截了DNS请求,需将Azure Event Hub域名加入允许列表。
  • 修正网络连通性测试:将测试命令中的.替换为实际命名空间前缀,执行.\psping.exe -n 25 -i 1 -q {你的命名空间}.servicebus.windows.net:5671 -nobanner,验证5671端口(AMQP协议端口)的出站连通性。内网环境需确认防火墙是否开放该端口的出站流量,或是否需要通过代理连接。
  • 检查证书与身份配置:
    • 确认证书未过期、密钥用法正确,且代码中使用的证书指纹与服务主体配置的一致。
    • 通过Azure门户"访问控制(IAM)"页面,验证服务主体的Event Hub角色分配是否正确应用到目标资源(命名空间或具体Event Hub)。
  • 更新SDK版本:确保使用的Azure.Messaging.EventHubs和Azure.Storage.Blobs NuGet包为最新稳定版本,旧版本可能存在已知的连接或DNS解析问题。

内容的提问来源于stack exchange,提问作者Catalin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 16:08:09