AddTransientHttpErrorPolicy(b => b.Or().WaitAndRetryAsync(Ĭ => TimeSpan.FromSeconds(Math.While using Masstransit 3.5 with Azure ServiceBus transport I've noticed several exceptions in logs (happening with multiple receive endpoints). Similarly, after 3rd retry, it will wait for 2 pow 3 = 8 second’s time. So, after first retry it will wait for 2 pow 1 = 2 seconds. This exponential retry is in the power of 2. I have specified total of 5 retries and there should be an exponential wait between retries. The AddTransientHttpErrorPolicy method is used to configure the wait and retry policy. AddPolicyHandler(Policy.TimeoutAsync(1)) I have specified this time to be 1 second. The AddPolicyHandler method is used to create a policy hander to specify how long to wait before a request is considered to be failed. Var commonEntities = processEntities.Join(orders, a => a.OrderId, b => b.Id, (a, b) => new ) Var processEntities = await repository.GetAllAsync(a => a.DroneId = droneId) Var orders = await orderClient.GetOrderAsync() Public async Task> GetAsync(Guid droneId) Public ProcessController(IRepository repository, OrderClient orderClient) Private readonly OrderClient orderClient Public class ProcessController : ControllerBase So add the highlighted code given below on the ConfigureServices() method. Now, we will need to register the methods, given on the Extensions.cs class, in the Startup.cs class. Return new MongoRepository(database, collectionName) Public static IServiceCollection AddMongoRepository(this IServiceCollection services, string collectionName) where T : IEntity Return mongoClient.GetDatabase(serviceSettings.ServiceName) Var mongoClient = new MongoClient(mongoDbSettings.ConnectionString) Var mongoDbSettings = configuration.GetSection(nameof(MongoDbSettings)).Get() Var serviceSettings = configuration.GetSection(nameof(ServiceSettings)).Get() Public static IServiceCollection AddMongo(this IServiceCollection services)īsonSerializer.RegisterSerializer(new GuidSerializer(BsonType.String)) īsonSerializer.RegisterSerializer(new DateTimeOffsetSerializer(BsonType.String)) Throw new ArgumentNullException(nameof(entity)) įilterDefinition filter = filterBuilder.Eq(e => e.Id, entity.Id) Īwait collection.ReplaceOneAsync(filter, entity) Public async Task GetAsync(Expression> filter) Return await collection.Find(filter).FirstOrDefaultAsync() Return await collection.Find(filter).ToListAsync() įilterDefinition filter = filterBuilder.Eq(e => e.Id, id) Public async Task> GetAllAsync(Expression> filter) Return await collection.Find(filterBuilder.Empty).ToListAsync() Public MongoRepository(IMongoDatabase database, string collectionName)Ĭollection = database.GetCollection(collectionName) Private readonly FilterDefinitionBuilder filterBuilder = Builders.Filter Private readonly IMongoCollection collection Public class MongoRepository : IRepository where T : IEntity There will be a MongoDB database which will store all this information. This Microservice will deal with delivery of Pizza Orders by drones. Next, click the create button to create this microservice. Select the template as ASP.NET Core Web API. Docker Container will run the MongoDB database.įirst open Visual Studio and create a new ASP.NET Core Web Application. MongoDB database will store data for the CRUD operations. The ProcessCenter Microservice is going to have very similar features to the first microservice, these features are: ASP.NET Core Microservices Code Refactoring into Reusable NuGet Package Creating ProcessCenter Microservice in ASP.NET Core Microservices Asynchronous Communication with RabbitMQ and MassTransit Microservices API Gateway to unify Multiple Microservices Synchronous Communication between Microservices built in ASP.NET Core First ASP.NET Core Microservice with Web API CRUD Operations on a MongoDB database This tutorial is a part of ASP.NET Core Microservices series.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |