Exemplo n.º 1
0
        async Task SendTransportMessage(string destinationAddress, TransportMessage transportMessage)
        {
            var transactionContext = GetCurrentTransactionContext(mustBelongToThisBus: true);

            if (transactionContext == null)
            {
                using (var context = new TransactionContext())
                {
                    await _transport.Send(destinationAddress, transportMessage, context).ConfigureAwait(false);

                    await context.Complete().ConfigureAwait(false);
                }
            }
            else
            {
                await _transport.Send(destinationAddress, transportMessage, transactionContext).ConfigureAwait(false);
            }
        }
Exemplo n.º 2
0
        async Task InnerSend(IEnumerable <string> destinationAddresses, Message logicalMessage)
        {
            var currentTransactionContext = GetCurrentTransactionContext(mustBelongToThisBus: true);

            if (currentTransactionContext != null)
            {
                await SendUsingTransactionContext(destinationAddresses, logicalMessage, currentTransactionContext).ConfigureAwait(false);
            }
            else
            {
                using (var context = new TransactionContext())
                {
                    await SendUsingTransactionContext(destinationAddresses, logicalMessage, context).ConfigureAwait(false);

                    await context.Complete().ConfigureAwait(false);
                }
            }
        }
Exemplo n.º 3
0
        async Task ProcessMessage(TransactionContext context, TransportMessage transportMessage)
        {
            try
            {
                context.Items["OwningBus"] = _owningBus;

                AmbientTransactionContext.SetCurrent(context);

                var incomingSteps = _pipeline.ReceivePipeline();
                var stepContext = new IncomingStepContext(transportMessage, context);
                await _pipelineInvoker.Invoke(stepContext, incomingSteps);

                try
                {
                    await context.Complete();
                }
                catch (Exception exception)
                {
                    _log.Error(exception, "An error occurred when attempting to complete the transaction context");
                }
            }
            catch (ThreadAbortException exception)
            {
                context.Abort();

                _log.Error(exception, $"Worker was killed while handling message {transportMessage.GetMessageLabel()}");
            }
            catch (Exception exception)
            {
                context.Abort();

                _log.Error(exception, $"Unhandled exception while handling message {transportMessage.GetMessageLabel()}");
            }
            finally
            {
                AmbientTransactionContext.SetCurrent(null);
            }
        }
Exemplo n.º 4
0
        async Task TimerElapsed()
        {
            using (var result = await _timeoutManager.GetDueMessages())
            {
                foreach (var dueMessage in result)
                {
                    var transportMessage = dueMessage.ToTransportMessage();
                    var returnAddress = transportMessage.Headers[Headers.DeferredRecipient];

                    _log.Debug("Sending due message {0} to {1}",
                        transportMessage.Headers[Headers.MessageId],
                        returnAddress);

                    using (var context = new TransactionContext())
                    {
                        await _transport.Send(returnAddress, transportMessage, context);

                        await context.Complete();
                    }

                    await dueMessage.MarkAsCompleted();
                }

                await result.Complete();
            }
        }