Пример #1
0
        /// <inheritdoc cref="IProducerBehavior.HandleAsync" />
        public async Task HandleAsync(ProducerPipelineContext context, ProducerBehaviorHandler next)
        {
            Check.NotNull(context, nameof(context));
            Check.NotNull(next, nameof(next));

            if (context.Envelope.Endpoint.Encryption != null && context.Envelope.RawMessage != null)
            {
                context.Envelope.RawMessage = _streamFactory.GetEncryptStream(
                    context.Envelope.RawMessage,
                    context.Envelope.Endpoint.Encryption);
            }

            await next(context).ConfigureAwait(false);
        }
        /// <inheritdoc cref="IProducerBehavior.HandleAsync" />
        public async Task HandleAsync(ProducerPipelineContext context, ProducerBehaviorHandler next)
        {
            Check.NotNull(context, nameof(context));
            Check.NotNull(next, nameof(next));

            if (context.Envelope.Endpoint.Encryption != null && context.Envelope.RawMessage != null)
            {
                context.Envelope.RawMessage = _streamFactory.GetEncryptStream(
                    context.Envelope.RawMessage,
                    context.Envelope.Endpoint.Encryption);

                if (context.Envelope.Endpoint.Encryption is SymmetricEncryptionSettings settings &&
                    settings.KeyIdentifier != null)
                {
                    context.Envelope.Headers.AddOrReplace(
                        DefaultMessageHeaders.EncryptionKeyId,
                        settings.KeyIdentifier);
                }
            }

            await next(context).ConfigureAwait(false);
        }