aspnetrun/run-aspnetcore-microservices

can you ensure Basket checkout atomicity

liuzhixin405 opened this issue · 4 comments

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!

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

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

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

Thanks,