【发布时间】:2022-12-19 11:54:45
【问题描述】:
我尝试使用以下设置通过 MassTransit 安全地连接到 Confluent Cloud 环境,但它似乎不起作用。我正在尝试在 .NET Core 中完成这项工作:
services.AddMassTransit(x =>
{
x.UsingRabbitMq((busRegistryContext, rabbitMQBusFactory) => rabbitMQBusFactory.ConfigureEndpoints(busRegistryContext));
x.AddRider(rider =>
{
rider.AddProducer<UserEvent>(topicName: "UserCreated");
rider.AddProducer<UserEvent>(topicName: "UserUpdated");
rider.AddProducer<UserEvent>(topicName: "UserDeleted");
rider.AddConsumer<UserCreatedEventConsumer>();
rider.UsingKafka((riderContext, kafkaFactory) =>
{
kafkaFactory.SecurityProtocol = Confluent.Kafka.SecurityProtocol.SaslSsl;
kafkaFactory.Host(server: "[hided...].westeurope.azure.confluent.cloud:9092", configureHost =>
{
configureHost.UseSasl(saslConfig =>
{
saslConfig.Mechanism = Confluent.Kafka.SaslMechanism.Plain;
saslConfig.Username = "...................";
saslConfig.Password = "...................";
});
});
var consumerConfig = new ConsumerConfig()
{
GroupId = "dotnet-example-group-1",
AutoOffsetReset = AutoOffsetReset.Latest,
EnableAutoCommit = false
};
kafkaFactory.TopicEndpoint<UserCreatedEvent>(
topicName: "UserCreated", consumerConfig, kafkaTopicReceiveEndpointConfig =>
{
kafkaTopicReceiveEndpointConfig.ConfigureConsumer<UserCreatedEventConsumer>(riderContext);
});
});
});
});
我收到以下错误:
MassTransit: Warning: Connection Failed: rabbitmq://localhost/
RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachable
---> System.AggregateException: One or more errors occurred. (Connection failed)
---> RabbitMQ.Client.Exceptions.ConnectFailureException: Connection failed
---> System.Net.Sockets.SocketException (10061): No connection could be made because the target machine actively refused it.
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
at System.Threading.Tasks.ValueTask.ValueTaskSourceAsTask.<>c.<.cctor>b__4_0(Object state)
--- End of stack trace from previous location ---
at RabbitMQ.Client.Impl.TcpClientAdapter.ConnectAsync(String host, Int32 port)
at RabbitMQ.Client.Impl.TaskExtensions.TimeoutAfter(Task task, TimeSpan timeout)
at RabbitMQ.Client.Impl.SocketFrameHandler.ConnectOrFail(ITcpClient socket, AmqpTcpEndpoint endpoint, TimeSpan timeout)
--- End of inner exception stack trace ---
at RabbitMQ.Client.Impl.SocketFrameHandler.ConnectOrFail(ITcpClient socket, AmqpTcpEndpoint endpoint, TimeSpan timeout)
at RabbitMQ.Client.Impl.SocketFrameHandler.ConnectUsingAddressFamily(AmqpTcpEndpoint endpoint, Func`2 socketFactory, TimeSpan timeout, AddressFamily family)
at RabbitMQ.Client.Impl.SocketFrameHandler..ctor(AmqpTcpEndpoint endpoint, Func`2 socketFactory, TimeSpan connectionTimeout, TimeSpan readTimeout, TimeSpan writeTimeout)
at RabbitMQ.Client.ConnectionFactory.CreateFrameHandler(AmqpTcpEndpoint endpoint)
at RabbitMQ.Client.EndpointResolverExtensions.SelectOne[T](IEndpointResolver resolver, Func`2 selector)
--- End of inner exception stack trace ---
at RabbitMQ.Client.EndpointResolverExtensions.SelectOne[T](IEndpointResolver resolver, Func`2 selector)
at RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver, String clientProvidedName)
--- End of inner exception stack trace ---
at RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver, String clientProvidedName)
at MassTransit.RabbitMqTransport.ConnectionContextFactory.CreateConnection(ISupervisor supervisor)
我实际上希望只连接到我的 Confluent Cloud Kafka 集群,但我是 MassTransit 和 Confluent Cloud 的新手,不明白为什么会这样(尽管我遵循了一些教程并仔细阅读了 MassTransit 文档)
【问题讨论】:
-
失败是连接到 RabbitMQ,而不是 Confluent Cloud。
-
@ChrisPatterson 对我如何解决这个问题有任何想法,因为我一直在寻找解决方案但找不到...
-
呃....
x.UsingRabbitMq((busRegistryContext, rabbitMQBusFactory) => rabbitMQBusFactory.ConfigureEndpoints(busRegistryContext)); -
正如我在第一条评论中所述,您发布的错误与 Confluent Cloud 无关。这表明本地主机上没有运行 RabbitMQ 代理。两个完全不同的东西,所以你的问题是无效的。
-
你知道我写的 MassTransit 对吗?所以我知道它是如何工作的。完全摆脱 RabbitMQ。你甚至不知道你在说什么。将其替换为
x.UsingInMemory()。
标签: .net apache-kafka masstransit confluent-cloud