【发布时间】:2020-07-31 13:40:04
【问题描述】:
我正在开发 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 |安全协议类型.Tls11 |安全协议类型.Tls;
【问题讨论】:
-
这绝对看起来像是服务拒绝连接,尽管我不知道为什么。您介意分享制作人是如何创建的吗?我想了解传输是为 TCP 还是 WebSockets 设置的。
-
producerClient = new EventHubProducerClient(connectionString),所以我希望使用默认的 tcp 连接
-
谢谢。你的假设是正确的; TCP 用作默认传输。不幸的是,由于这似乎发生在服务中,因此我无法从客户的角度提供太多见解。我会跟进事件中心服务团队并请求他们提供帮助。
-
您是否启用了 IP 过滤器或 VNET?
-
azure 门户账户中没有 ip 过滤或 vnet 配置,它的配置接近默认值。以前我公司的防火墙有问题,但在这个阶段我得到了 System.Net.Sockets.SocketException(现在已修复)。
标签: c# .net-core azure-eventhub