/// <summary>
        ///     <para>
        ///         Sets the serializer to an instance of <see cref="BinaryFileMessageSerializer" /> (or
        ///         <see cref="BinaryFileMessageSerializer{TMessage}" />) to produce the <see cref="BinaryFileMessage" />.
        ///     </para>
        ///     <para>
        ///         By default this serializer forwards the message type in an header to let the consumer know which
        ///         type has to be deserialized. This approach allows to mix messages of different types in the same
        ///         endpoint and it's ideal when both the producer and the consumer are using Silverback but might not
        ///         be optimal for interoperability. This behavior can be changed using the builder action and
        ///         specifying the model to be used.
        ///     </para>
        /// </summary>
        /// <remarks>
        ///     This replaces the <see cref="IMessageSerializer" /> and the endpoint will only be able to deal with
        ///     binary files.
        /// </remarks>
        /// <typeparam name="TBuilder">
        ///     The actual builder type.
        /// </typeparam>
        /// <param name="endpointBuilder">
        ///     The endpoint builder.
        /// </param>
        /// <param name="serializerBuilderAction">
        ///     An optional <see cref="Action{T}" /> that takes the <see cref="IBinaryFileMessageSerializerBuilder" />
        ///     and configures it.
        /// </param>
        /// <returns>
        ///     The endpoint builder so that additional calls can be chained.
        /// </returns>
        public static TBuilder ProduceBinaryFiles <TBuilder>(
            this IProducerEndpointBuilder <TBuilder> endpointBuilder,
            Action <IBinaryFileMessageSerializerBuilder>?serializerBuilderAction = null)
            where TBuilder : IProducerEndpointBuilder <TBuilder>
        {
            Check.NotNull(endpointBuilder, nameof(endpointBuilder));

            var serializerBuilder = new BinaryFileMessageSerializerBuilder();

            serializerBuilderAction?.Invoke(serializerBuilder);
            endpointBuilder.SerializeUsing(serializerBuilder.Build());

            return((TBuilder)endpointBuilder);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     <para>
        ///         Sets the serializer to an instance of <see cref="NewtonsoftJsonMessageSerializer" /> (or
        ///         <see cref="NewtonsoftJsonMessageSerializer{TMessage}" />) to serialize the produced messages as
        ///         JSON.
        ///     </para>
        ///     <para>
        ///         By default this serializer forwards the message type in an header to let the consumer know which
        ///         type has to be deserialized. This approach allows to mix messages of different types in the same
        ///         endpoint and it's ideal when both the producer and the consumer are using Silverback but might not
        ///         be optimal for interoperability. This behavior can be changed using the builder action and
        ///         specifying a fixed message type.
        ///     </para>
        /// </summary>
        /// <typeparam name="TBuilder">
        ///     The actual builder type.
        /// </typeparam>
        /// <param name="endpointBuilder">
        ///     The endpoint builder.
        /// </param>
        /// <param name="serializerBuilderAction">
        ///     An optional <see cref="Action{T}" /> that takes the
        ///     <see cref="INewtonsoftJsonMessageSerializerBuilder" /> and configures it.
        /// </param>
        /// <returns>
        ///     The endpoint builder so that additional calls can be chained.
        /// </returns>
        public static TBuilder SerializeAsJsonUsingNewtonsoft <TBuilder>(
            this IProducerEndpointBuilder <TBuilder> endpointBuilder,
            Action <INewtonsoftJsonMessageSerializerBuilder>?serializerBuilderAction = null)
            where TBuilder : IProducerEndpointBuilder <TBuilder>
        {
            Check.NotNull(endpointBuilder, nameof(endpointBuilder));

            var serializerBuilder = new NewtonsoftJsonMessageSerializerBuilder();

            serializerBuilderAction?.Invoke(serializerBuilder);
            endpointBuilder.SerializeUsing(serializerBuilder.Build());

            return((TBuilder)endpointBuilder);
        }
        /// <summary>
        ///     Specifies that the AES algorithm has to be used to encrypt the messages.
        /// </summary>
        /// <typeparam name="TBuilder">
        ///     The actual builder type.
        /// </typeparam>
        /// <param name="endpointBuilder">
        ///     The endpoint builder.
        /// </param>
        /// <param name="key">
        ///     The secret key for the symmetric algorithm.
        /// </param>
        /// <param name="initializationVector">
        ///     The optional initialization vector (IV) for the symmetric algorithm. If <c>null</c> a different IV
        ///     will be generated for each message and prepended to the actual message payload.
        /// </param>
        /// <returns>
        ///     The endpoint builder so that additional calls can be chained.
        /// </returns>
        public static TBuilder EncryptUsingAes <TBuilder>(
            this IProducerEndpointBuilder <TBuilder> endpointBuilder,
            byte[] key,
            byte[]?initializationVector = null)
            where TBuilder : IProducerEndpointBuilder <TBuilder>
        {
            Check.NotNull(endpointBuilder, nameof(endpointBuilder));

            endpointBuilder.Encrypt(
                new SymmetricEncryptionSettings
            {
                AlgorithmName        = "AES",
                Key                  = key,
                InitializationVector = initializationVector
            });

            return((TBuilder)endpointBuilder);
        }