dotnetcore / CAP

Distributed transaction solution in micro-service base on eventually consistency, also an eventbus with Outbox pattern
http://cap.dotnetcore.xyz
MIT License
6.61k stars 1.28k forks source link

.NET Core 8 使用RabbitMQ 报No ip address could be resolved for【hostName】的问题 #1534

Closed wangyimingok closed 3 months ago

wangyimingok commented 3 months ago

按照文档说明的配置 /// <summary> /// 添加CAP事件总线 /// </summary> /// <param name="services"></param> /// <param name="rootConfiguration"></param> public static void AddCAPEventBus(this IServiceCollection services, IRootConfiguration rootConfiguration) { var sqlConnectionStr = rootConfiguration?.ConnectionString?.LeCakeOMSDataBaseConnectionString; var RabbitMQConfig = rootConfiguration?.RabbitConfiguration; services.AddCap(option => { option.GroupNamePrefix = OMSRabbitMQConstant.GroupNamePrefix; option.UseDashboard(option => { option.AllowAnonymousExplicit = true; }); option.UseSqlServer(sqlConnectionStr); option.UseRabbitMQ(RabbitConfig => { RabbitConfig.Port = RabbitMQConfig.PortNumber; RabbitConfig.HostName = RabbitMQConfig.HostName; RabbitConfig.UserName = RabbitMQConfig.UserName; RabbitConfig.Password = RabbitMQConfig.Password; if (!string.IsNullOrWhiteSpace(RabbitMQConfig.VirtualHost)) { RabbitConfig.VirtualHost = RabbitMQConfig.VirtualHost; } if (!string.IsNullOrWhiteSpace(RabbitMQConfig.ExchangeName)) { RabbitConfig.ExchangeName = RabbitMQConfig.ExchangeName; } //RabbitConfig.ConnectionFactoryOptions = opt => { // opt.HostName = RabbitMQConfig.HostName; // opt.Port= RabbitMQConfig.PortNumber; // opt.UserName= RabbitMQConfig.UserName; // opt.Uri = new Uri($"amqp://{RabbitMQConfig.UserName}:{RabbitMQConfig.Password}@{RabbitMQConfig.HostName}:{RabbitMQConfig.PortNumber}"); //}; }); option.FailedRetryCount = 10; option.FailedThresholdCallback = failed => { var logger = failed.ServiceProvider.GetService<ILogger<CapOptions>>(); logger.LogError( $@"A message of type {failed.MessageType} failed after executing {option.FailedRetryCount} several times, requiring manual troubleshooting. Message name: {failed.Message.GetName()}"); }; }); }

其中rootConfiguration的配置文件为: "RabbitConfiguration": { "HostName": "192.168.0.89", "PortNumber": 5672, "UserName": "dev", "Password": "123123", "VirtualHost": "OMS", "ExchangeName": "OMS" }, 程序运行起来一直会报:No ip address could be resolved for 192.168.0.89

yang-xiaodong commented 3 months ago

Have you tried making a connection using only the RabbitMQ client directly?