.Net Core,Eventhub:身份验证失败,因为远程方已关闭传输流

.Net Core, Eventhub: Authentication failed because the remote party has closed the transport stream

我正在开发 EventHub 的制作人。在部署到我们的测试环境后,它在本地工作正常 - 我收到错误“身份验证失败,因为远程方已关闭传输流。”

Docker 图片:mcr.microsoft.com/dotnet/core/aspnet:3.1

使用的代码:

await using (var producerClient = new EventHubProducerClient(connectionString))
                {
                    var eventData = new EventData(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(message)));

                    var batch = await producerClient.CreateBatchAsync();
                    batch.TryAdd(eventData);
                    await producerClient.SendAsync(batch);
                }

堆栈跟踪:

at System.Net.Security.SslStream.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)\n  
at System.Net.Security.SslStream.PartialFrameCallback(AsyncProtocolRequest asyncRequest)\n
--- End of stack trace from previous location where exception was thrown ---\n  
at System.Net.Security.SslStream.ThrowIfExceptional()\n 
at System.Net.Security.SslStream.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)\n 
at System.Net.Security.SslStream.EndProcessAuthentication(IAsyncResult result)\n   a
t System.Net.Security.SslStream.EndAuthenticateAsClient(IAsyncResult asyncResult)\n 
at System.Net.Security.SslStream.<>c.<AuthenticateAsClientAsync>b__64_2(IAsyncResult iar)\n 
at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)\n
--- End of stack trace from previous location where exception was thrown ---\n
at Microsoft.Azure.Amqp.TaskHelpers.EndAsyncResult(IAsyncResult asyncResult)\n 
at Microsoft.Azure.Amqp.StreamExtensions.EndAuthenticateAsClient(SslStream sslStream, IAsyncResult asyncResult)\n
at Microsoft.Azure.Amqp.Transport.TlsTransport.HandleOpenComplete(IAsyncResult result, Boolean syncComplete)\n
--- End of stack trace from previous location where exception was thrown ---\n 
at Microsoft.Azure.Amqp.ExceptionDispatcher.Throw(Exception exception)\n
at Microsoft.Azure.Amqp.AsyncResult.End[TAsyncResult](IAsyncResult result)\n  
at Microsoft.Azure.Amqp.AmqpObject.OpenAsyncResult.End(IAsyncResult result)\n  
at Microsoft.Azure.Amqp.AmqpObject.EndOpen(IAsyncResult result)\n  
at Microsoft.Azure.Amqp.Transport.TlsTransportInitiator.HandleTransportOpened(IAsyncResult result)\n
at Microsoft.Azure.Amqp.Transport.TlsTransportInitiator.OnTransportOpened(IAsyncResult result)\n
--- End of stack trace from previous location where exception was thrown    ---\n 
at Azure.Messaging.EventHubs.Amqp.AmqpConnectionScope.CreateAndOpenConnectionAsync(Version amqpVersion, Uri serviceEndpoint, EventHubsTransportType transportType, IWebProxy proxy, String scopeIdentifier, TimeSpan timeout)\n
at Microsoft.Azure.Amqp.FaultTolerantAmqpObject`1.OnCreateAsync(TimeSpan timeout)\n 
at Microsoft.Azure.Amqp.Singleton`1.GetOrCreateAsync(TimeSpan timeout)\n 
at Microsoft.Azure.Amqp.Singleton`1.GetOrCreateAsync(TimeSpan timeout)\n  
at Azure.Messaging.EventHubs.Amqp.AmqpConnectionScope.OpenProducerLinkAsync(String partitionId, TimeSpan timeout, CancellationToken cancellationToken)\n   at Azure.Messaging.EventHubs.Amqp.AmqpProducer.CreateLinkAndEnsureProducerStateAsync(String partitionId, TimeSpan timeout, CancellationToken cancellationToken)\n   at Microsoft.Azure.Amqp.FaultTolerantAmqpObject`1.OnCreateAsync(TimeSpan timeout)\n
at Microsoft.Azure.Amqp.Singleton`1.GetOrCreateAsync(TimeSpan timeout)\n 
at Microsoft.Azure.Amqp.Singleton`1.GetOrCreateAsync(TimeSpan timeout)\n  
at Azure.Messaging.EventHubs.Amqp.AmqpProducer.CreateBatchAsync(CreateBatchOptions options, CancellationToken cancellationToken)\n  
at Azure.Messaging.EventHubs.Amqp.AmqpProducer.CreateBatchAsync(CreateBatchOptions options, CancellationToken cancellationToken)\n  
at Azure.Messaging.EventHubs.Producer.EventHubProducerClient.CreateBatchAsync(CreateBatchOptions options, CancellationToken cancellationToken)\n   at Azure.Messaging.EventHubs.Producer.EventHubProducerClient.CreateBatchAsync(CancellationToken cancellationToken)\n",

附加数据: 已尝试按照类似主题中的建议添加此内容,但没有帮助

ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

有重要信息未提及 - 服务是通过 Kubernetes 在 docker 中部署的。

此错误与我们公司内部的防火墙设置有关。