Пример #1
0
        public async Task <CompensationResult> Compensate(CompensateContext <AllocateInventoryLog> context)
        {
            await context.Publish <AllocationReleaseRequested>(new
            {
                AllocationId = context.Log.AllocationId,
                Reason       = "Order Faulted"
            });

            return(context.Compensated());
        }
Пример #2
0
        public async Task <CompensationResult> Compensate(CompensateContext <BookFlightLogs> context)
        {
            await Task.Delay(BookItem.LongDelay);

            var protocols = new IHubProtocol[] { new JsonHubProtocol() };
            await context.Publish <All <ChatHub> >(new
            {
                Messages = protocols.ToProtocolDictionary("ReceiveMessage", new object[] { "message", $"Flight {context.Log.Message} was canceled!" })
            });

            return(context.Compensated());
        }
Пример #3
0
        public async Task <CompensationResult> Compensate(CompensateContext <IBookHotelActivityLog> context)
        {
            this._logger.LogWarning($"Compensating {nameof(BookHotelActivity)} activity" +
                                    $"\r\nCompensation log: {JsonConvert.SerializeObject(context.Log)}");

            await context.Publish <ICancelHotelBooking>(new
            {
                context.Log.BookingId
            });

            return(context.Compensated());
        }
        public async Task <CompensationResult> Compensate(CompensateContext <AllocateInventoryLog> context)
        {
            // 지금까지 해오던 작업을 Rollback 하는 시나리오가 발생.
            _logger.LogWarning("AllocateInventory 작업을 되돌립니다...");

            // 현 Activity(=Allocate Inventory, 재고할당)수준에서 Rollback 할 수 있는 처리가 여기 들어감
            // 예를 들면, "재고할당을 취소" 하는 요청을 보내는 작업...
            await context.Publish <AllocationReleaseRequested>(new
            {
                AllocationId = context.Log.AllocationId,
                Reason       = "주문 오류 발생"
            });

            // 이 Activity 는 Rollback을 위한 작업이 완료되었음을 반환.
            // ("Compenste(보상)" 이라는 의미는 어떤 변경에 대하여 없었던것으로
            //              "보상"하는 방식으로 Masstransit.Courier 가 동작하기 때문)
            return(context.Compensated());
        }
Пример #5
0
        public async Task <CompensationResult> Compensate(CompensateContext <GeraLancamentoLog> context)
        {
            using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                var transacaoOriginal = Repositorio.PegaTransacao(context.Log.IdLancamento);

                if (transacaoOriginal == null)
                {
                    return(context.Compensated());
                }

                var novoSaldo = Repositorio.AdicionaTransacao(
                    new Transacao(Guid.NewGuid(),
                                  DateTime.Now,
                                  "Estorno " + transacaoOriginal.Id,
                                  transacaoOriginal.Conta, -transacaoOriginal.Valor));


                await context.Publish(new SaldoAtualizado(transacaoOriginal.Conta, novoSaldo));

                scope.Complete();
                return(context.Compensated());
            }
        }
 Task IPublishEndpoint.Publish <T>(T message, CancellationToken cancellationToken)
 {
     return(_context.Publish(message, cancellationToken));
 }