aspnetrun / run-aspnetcore-microservices

Microservices on .Net platforms which used ASP.NET Web API, Docker, RabbitMQ, MassTransit, Grpc, Yarp API Gateway, PostgreSQL, Redis, SQLite, SqlServer, Marten, Entity Framework Core, CQRS, MediatR, DDD, Vertical and Clean Architecture implementation with using latest features of .NET 8 and C# 12
https://www.udemy.com/course/microservices-architecture-and-implementation-on-dotnet/?couponCode=JUNE24
MIT License
2.53k stars 1.38k forks source link

System.TimeoutException error when I run Catalog.API #28

Closed msh2050 closed 3 years ago

msh2050 commented 3 years ago

I get this error when I run Catalog.API solution

ducker installed and the container is working...

System.TimeoutException: 'A timeout occurred after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : "1", Type : "Unknown", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "Unspecified/catalogdb:27017" }", EndPoint: "Unspecified/catalogdb:27017", ReasonChanged: "Heartbeat", State: "Disconnected", ServerVersion: , TopologyVersion: , Type: "Unknown", HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> System.Net.Sockets.SocketException (11001): No such host is known. at System.Net.NameResolutionPal.ProcessResult(SocketError errorCode, GetAddrInfoExContext* context) at System.Net.NameResolutionPal.GetAddressInfoExCallback(Int32 error, Int32 bytes, NativeOverlapped* overlapped) --- End of stack trace from previous location --- at MongoDB.Driver.Core.Connections.TcpStreamFactory.ResolveEndPointsAsync(EndPoint initial) at MongoDB.Driver.Core.Connections.TcpStreamFactory.CreateStreamAsync(EndPoint endPoint, CancellationToken cancellationToken) at MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelperAsync(CancellationToken cancellationToken) --- End of inner exception stack trace --- at MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelperAsync(CancellationToken cancellationToken) at MongoDB.Driver.Core.Servers.ServerMonitor.InitializeConnectionAsync(CancellationToken cancellationToken) at MongoDB.Driver.Core.Servers.ServerMonitor.HeartbeatAsync(CancellationToken cancellationToken)", LastHeartbeatTimestamp: "2021-06-23T18:18:01.2912448Z", LastUpdateTimestamp: "2021-06-23T18:18:01.2912453Z" }] }.'

msh2050 commented 3 years ago

the issue in getting the value by IConfiguration interface from the "appsettings.json"

  "DatabaseSettings": {
    "ConnectionString": "mongodb://localhost:27017",
    "DatabaseName": "CatalogDb",
    "CollectionName": "Products"
  },

if I add this code:

            var clientTxt = configuration.GetValue<string>("DatabaseSettings:ConnectionString");
            var databasTxt = configuration.GetValue<string>("DatabaseSettings:DatabaseName");
            var producTxt = configuration.GetValue<string>("DatabaseSettings:CollectionName");
            Console.Write($"client: {clientTxt} \ndatabase: {databasTxt} \nproduct {producTxt}");

I will get

client: mongodb://catalogdb:27017
database: ProductDb
product Products
msh2050 commented 3 years ago

sorry this is because it get the settings from appsettings.Development.json just corrected that and it is ok

clossing this