/// <summary>
        /// Carries out whichever logic it takes to do something good for the outgoing message :)
        /// </summary>
        public async Task Process(OutgoingStepContext context, Func<Task> next)
        {
            var transactionContext = context.Load<ITransactionContext>();

            object temp;
            if (transactionContext.Items.TryGetValue(HandlerInvoker.CurrentHandlerInvokerItemsKey, out temp))
            {
                var handlerInvoker = (HandlerInvoker)temp;

                if (handlerInvoker.HasSaga)
                {
                    var idempotentSagaData = handlerInvoker.GetSagaData() as IIdempotentSagaData;

                    if (idempotentSagaData != null)
                    {
                        var idempotencyData = idempotentSagaData.IdempotencyData;

                        var transportMessage = context.Load<TransportMessage>();
                        var destinationAddresses = context.Load<DestinationAddresses>();
                        var incomingStepContext = transactionContext.Items.GetOrThrow<IncomingStepContext>(StepContext.StepContextKey);
                        var messageId = incomingStepContext.Load<Message>().GetMessageId();

                        idempotencyData.AddOutgoingMessage(messageId, destinationAddresses, transportMessage);
                    }
                }
            }

            await next();
        }
        public async Task Process(OutgoingStepContext context, Func<Task> next)
        {
            var message = context.Load<Message>();
            var headers = message.Headers;
            var messageBodyToSend = PossiblyConvertBody(headers, message.Body);
            var body = new[]{messageBodyToSend};
            
            context.Save(new Message(headers, body));

            await next();
        }
 public async Task CanCaptureIdentityInTheMessage()
 {
     var step = new CapturePrincipalInOutgoingMessage(new DummySerializer());
     var instance = new Message(new Dictionary<string, string>(), new object());
     var context = new OutgoingStepContext(instance, new DefaultTransactionContext(),
         new DestinationAddresses(new[] { "Larry" }));
     
     context.Save(instance);
     await step.Process(context, async () => { });
     Assert.That(instance.Headers.ContainsKey(CapturePrincipalInOutgoingMessage.PrincipalCaptureKey));
     Assert.AreEqual(instance.Headers[CapturePrincipalInOutgoingMessage.PrincipalCaptureKey], "Larry");
 }
        public async Task Process(OutgoingStepContext context, Func<Task> next)
        {
            var message = context.Load<Message>();
            var headers = message.Headers;
            var currentClaimsPrincipal = ClaimsPrincipal.Current;

            if (currentClaimsPrincipal != null && !headers.ContainsKey(PrincipalCaptureKey))
            {
                headers[PrincipalCaptureKey] = _serializer.Serialize(currentClaimsPrincipal);
            }

            await next();
        }
        /// <summary>
        /// Invokes the pipeline of <see cref="IOutgoingStep"/> steps, passing the given <see cref="OutgoingStepContext"/> to each step as it is invoked
        /// </summary>
        public async Task Invoke(OutgoingStepContext context, IEnumerable<IOutgoingStep> pipeline)
        {
            var receivePipeline = pipeline.ToArray();
            var step = TerminationStep;

            for (var index = receivePipeline.Length - 1; index >= 0; index--)
            {
                var nextStep = step;
                var stepToInvoke = receivePipeline[index];
                step = () => stepToInvoke.Process(context, nextStep);
            }

            await step();
        }
Beispiel #6
0
        /// <summary>
        /// Invokes the pipeline of <see cref="IOutgoingStep"/> steps, passing the given <see cref="OutgoingStepContext"/> to each step as it is invoked
        /// </summary>
        public Task Invoke(OutgoingStepContext context, IEnumerable <IOutgoingStep> pipeline)
        {
            var receivePipeline = GetPipeline(pipeline);
            var step            = TerminationStep;

            for (var index = receivePipeline.Length - 1; index >= 0; index--)
            {
                var nextStep     = step;
                var stepToInvoke = receivePipeline[index];
                step = () => stepToInvoke.Process(context, nextStep);
            }

            return(step());
        }
        /// <summary>
        /// Invokes the pipeline of <see cref="IOutgoingStep"/> steps, passing the given <see cref="OutgoingStepContext"/> to each step as it is invoked
        /// </summary>
        public async Task Invoke(OutgoingStepContext context, IEnumerable <IOutgoingStep> pipeline)
        {
            var receivePipeline = pipeline.ToArray();
            var step            = TerminationStep;

            for (var index = receivePipeline.Length - 1; index >= 0; index--)
            {
                var nextStep     = step;
                var stepToInvoke = receivePipeline[index];
                step = () => stepToInvoke.Process(context, nextStep);
            }

            await step();
        }
        /// <summary>
        /// Encrypts the outgoing <see cref="TransportMessage"/> and adds appropriate headers
        /// </summary>
        public async Task Process(OutgoingStepContext context, Func<Task> next)
        {
            var transportMessage = context.Load<TransportMessage>();

            var headers = transportMessage.Headers.Clone();
            var bodyBytes = transportMessage.Body;
            var encryptedData = _encryptor.Encrypt(bodyBytes);
            
            headers[EncryptionHeaders.ContentEncryption] = "rijndael";
            headers[EncryptionHeaders.ContentInitializationVector] = Convert.ToBase64String(encryptedData.Iv);
            context.Save(new TransportMessage(headers, encryptedData.Bytes));

            await next();
        }
        public async Task Process(OutgoingStepContext context, Func<Task> next)
        {
            var transportMessage = context.Load<TransportMessage>();

            var body = transportMessage.Body;
            var headers = transportMessage.Headers;

            var newHeaders = MapTrivialHeaders(headers);

            MapSpecialHeaders(newHeaders);

            context.Save(new TransportMessage(newHeaders, body));

            await next();
        }
        public async Task Process(OutgoingStepContext context, Func<Task> next)
        {
            var transportMessage = context.Load<TransportMessage>();

            if (IsPublishedMessage(transportMessage))
            {
                var transactionContext = context.Load<ITransactionContext>();

                var clone = transportMessage.Clone();
                clone.Headers[Headers.AuditTime] = RebusTime.Now.ToString("O");

                await _transport.Send(_auditQueue, clone, transactionContext);
            }

            await next();
        }
        public async Task Process(OutgoingStepContext context, Func<Task> next)
        {
            var transportMessage = context.Load<TransportMessage>();

            if (IsPublishedMessage(transportMessage))
            {
                var transactionContext = context.Load<ITransactionContext>();

                var clone = transportMessage.Clone();

                _auditingHelper.SetCommonHeaders(clone);

                await _transport.Send(_auditingHelper.AuditQueue, clone, transactionContext);
            }

            await next();
        }
Beispiel #12
0
        void PossiblyCompressTransportMessage(OutgoingStepContext context)
        {
            var transportMessage = context.Load<TransportMessage>();

            if (transportMessage.Body == null) return;

            if (transportMessage.Body.Length < _bodySizeThresholdBytes) return;

            var headers = transportMessage.Headers.Clone();
            var compressedBody = _zipper.Zip(transportMessage.Body);
            
            headers[Headers.ContentEncoding] = GzipEncodingHeader;

            var compressedTransportMessage = new TransportMessage(headers, compressedBody);

            context.Save(compressedTransportMessage);
        }
        public async Task Process(OutgoingStepContext context, Func<Task> next)
        {
            var message = context.Load<Message>();

            var body = message.Body;

            if (body != null)
            {
                var interfaces = body.GetType().GetInterfaces();

                if (interfaces.Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IFailed<>)))
                {
                    throw new InvalidOperationException($"Tried to send {body} - it is not allowed to send an IFailed<TMessage> anywhere because a) it most likely is an error, because you accidentally called Send/Defer with 'failed' and not with 'failed.Message' as the argument, and b) it could confuse things a lot - we like to avoid confusing things");
                }
            }

            await next();
        }
Beispiel #14
0
        async Task SendUsingTransactionContext(IEnumerable<string> destinationAddresses, Message logicalMessage, ITransactionContext transactionContext)
        {
            var context = new OutgoingStepContext(logicalMessage, transactionContext, new DestinationAddresses(destinationAddresses));

            await _pipelineInvoker.Invoke(context, _pipeline.SendPipeline());
        }
Beispiel #15
0
 /// <summary>
 /// Compresses theo outgoing transport message body
 /// </summary>
 public async Task Process(OutgoingStepContext context, Func<Task> next)
 {
     PossiblyCompressTransportMessage(context);
     
     await next();
 }