aspnetrun / run-aspnetcore-microservices

Microservices on .NET platforms 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=SEPT24
MIT License
2.7k stars 1.46k forks source link

can you ensure Basket checkout atomicity #56

Closed liuzhixin405 closed 2 years ago

liuzhixin405 commented 2 years ago

in basket api basketcontroller Checkout:


var basket = await _repository.GetBasket(basketCheckout.UserName); if (basket == null) { return BadRequest(); }

        // send checkout event to rabbitmq
        var eventMessage = _mapper.Map<BasketCheckoutEvent>(basketCheckout);
        eventMessage.TotalPrice = basket.TotalPrice;
        await _publishEndpoint.Publish<BasketCheckoutEvent>(eventMessage);

        // remove the basket
        await _repository.DeleteBasket(basket.UserName);

        return Accepted();

if MassTransit publish or IBasketRepository delete fail,the checkout business is fail . can you use the transcation to achieve checkout 's atomicity ,fianlly this is comply eventual consistency, thank you!

liuzhixin405 commented 2 years ago

...

tutul2010 commented 10 months ago

Hi @liuzhixin405 -

Did get the resolution of question u asked? How to mention the eventual consistency in basket and Order api services? @mehmetozkaya - any idea for implementation of sage or database level distribution handling mechanism for above situation?

Thanks, Tutul

liuzhixin405 commented 10 months ago

Hi @liuzhixin405 - Did get the question u ask? How to mention the eventual consistency in basket and Order api services? @mehmetozkaya - any idea for implementation of sage or database level distribution handling mechanism for above situation?

Thanks, Tutul It's been a long time since this problem,you can you outbox pattern like this
https://github.com/liuzhixin405/outboxpattern

tutul2010 commented 10 months ago

Thanks @liuzhixin405 for directions. I will check code repo .

Thanks,