/// <summary>
 /// Registers a middleware to compress the message
 /// </summary>
 /// <param name="middlewares"></param>
 /// <param name="factory">A factory to create the <see cref="IMessageCompressor"/> instance</param>
 public static IProducerMiddlewareConfigurationBuilder AddCompressor <T>(
     this IProducerMiddlewareConfigurationBuilder middlewares,
     Factory <T> factory)
     where T : class, IMessageCompressor
 {
     return(middlewares.Add(resolver => new CompressorProducerMiddleware(factory(resolver))));
 }
 /// <summary>
 /// Registers a middleware to serialize avro messages using schema registry
 /// </summary>
 /// <param name="middlewares">The middleware configuration builder</param>
 /// <param name="config">The avro serializer configuration</param>
 /// <returns></returns>
 public static IProducerMiddlewareConfigurationBuilder AddSchemaRegistryAvroSerializer(
     this IProducerMiddlewareConfigurationBuilder middlewares,
     AvroSerializerConfig config = null)
 {
     return(middlewares.AddSerializer(
                resolver => new ConfluentAvroSerializer(resolver, config),
                resolver => new SchemaRegistryTypeResolver(new ConfluentAvroTypeNameResolver(resolver.Resolve <ISchemaRegistryClient>()))));
 }
Beispiel #3
0
 /// <summary>
 /// Registers a middleware to serialize messages
 /// </summary>
 /// <typeparam name="TSerializer">A class that implements <see cref="IMessageSerializer"/></typeparam>x
 public static IProducerMiddlewareConfigurationBuilder AddSerializer <TSerializer>(
     this IProducerMiddlewareConfigurationBuilder producer)
     where TSerializer : class, IMessageSerializer
 {
     return(producer.AddSerializer(
                resolver => resolver.Resolve <TSerializer>(),
                resolver => resolver.Resolve <DefaultMessageTypeResolver>()));
 }
Beispiel #4
0
 /// <summary>
 /// Registers a middleware to serialize json messages using schema registry
 /// </summary>
 /// <param name="middlewares">The middleware configuration builder</param>
 /// <param name="config">The protobuf serializer configuration</param>
 /// <typeparam name="TMessage">The message type</typeparam>
 /// <returns></returns>
 public static IProducerMiddlewareConfigurationBuilder AddSchemaRegistryJsonSerializer <TMessage>(
     this IProducerMiddlewareConfigurationBuilder middlewares,
     JsonSerializerConfig config = null)
 {
     return(middlewares.AddSerializer(
                resolver => new ConfluentJsonSerializer(resolver, config),
                _ => new SingleMessageTypeResolver(typeof(TMessage))));
 }
 /// <summary>
 /// Register a middleware to serialize the message to a fixed type
 /// </summary>
 /// <param name="middlewares"></param>
 /// <param name="serializerFactory">A factory to create a <see cref="IMessageSerializer"/></param>
 /// <typeparam name="TMessage">The message type</typeparam>
 /// <typeparam name="TSerializer">A class that implements <see cref="IMessageSerializer"/></typeparam>
 /// <returns></returns>
 public static IProducerMiddlewareConfigurationBuilder AddSingleTypeSerializer <TMessage, TSerializer>(
     this IProducerMiddlewareConfigurationBuilder middlewares,
     Factory <TSerializer> serializerFactory)
     where TSerializer : class, IMessageSerializer
 {
     return(middlewares.AddSerializer(
                serializerFactory,
                resolver => new SingleMessageTypeResolver <TMessage>()));
 }
Beispiel #6
0
 /// <summary>
 /// Registers a middleware to serialize messages
 /// </summary>
 /// <param name="middlewares">The middleware configuration builder</param>
 /// <typeparam name="TSerializer">A class that implements <see cref="ISerializer"/></typeparam>
 /// <param name="serializerFactory">A factory to create a <see cref="ISerializer"/></param>
 /// <returns></returns>
 public static IProducerMiddlewareConfigurationBuilder AddSerializer <TSerializer>(
     this IProducerMiddlewareConfigurationBuilder middlewares,
     Factory <TSerializer> serializerFactory)
     where TSerializer : class, ISerializer
 {
     return(middlewares.AddSerializer(
                serializerFactory,
                _ => new DefaultTypeResolver()));
 }
Beispiel #7
0
        /// <summary>
        /// Registers a middleware to serialize messages
        /// </summary>
        /// <param name="middlewares">The middleware configuration builder</param>
        /// <typeparam name="TSerializer">A class that implements <see cref="ISerializer"/></typeparam>
        /// <returns></returns>x
        public static IProducerMiddlewareConfigurationBuilder AddSerializer <TSerializer>(
            this IProducerMiddlewareConfigurationBuilder middlewares)
            where TSerializer : class, ISerializer
        {
            middlewares.DependencyConfigurator.AddTransient <TSerializer>();

            return(middlewares.AddSerializer(
                       resolver => resolver.Resolve <TSerializer>(),
                       _ => new DefaultTypeResolver()));
        }
        /// <summary>
        /// Register a middleware to compress the message
        /// </summary>
        /// <typeparam name="T">A class that implements <see cref="IMessageCompressor"/></typeparam>
        /// <param name="middlewares"></param>
        /// <param name="factory">A factory to create the <see cref="IMessageCompressor"/> instance</param>
        public static IProducerMiddlewareConfigurationBuilder AddCompressor <T>(
            this IProducerMiddlewareConfigurationBuilder middlewares,
            Factory <T> factory)
            where T : class, IMessageCompressor
        {
            middlewares.DependencyConfigurator.AddSingleton <IMessageCompressor, T>();
            middlewares.DependencyConfigurator.AddSingleton <T>();

            return(middlewares.Add(
                       provider => new CompressorProducerMiddleware(factory(provider))));
        }
Beispiel #9
0
        /// <summary>
        /// Register a middleware to serialize the message to a fixed type
        /// </summary>
        /// <param name="middlewares">The middleware configuration builder</param>
        /// <param name="messageType">The message type</param>
        /// <typeparam name="TSerializer">A class that implements <see cref="ISerializer"/></typeparam>
        /// <returns></returns>
        public static IProducerMiddlewareConfigurationBuilder AddSingleTypeSerializer <TSerializer>(
            this IProducerMiddlewareConfigurationBuilder middlewares,
            Type messageType)
            where TSerializer : class, ISerializer
        {
            middlewares.DependencyConfigurator.AddTransient <TSerializer>();

            return(middlewares.AddSerializer(
                       resolver => resolver.Resolve <TSerializer>(),
                       _ => new SingleMessageTypeResolver(messageType)));
        }
 /// <summary>
 /// Registers a middleware to serialize messages
 /// </summary>
 /// <typeparam name="TSerializer">A class that implements <see cref="IMessageSerializer"/></typeparam>
 /// <typeparam name="TResolver">A class that implements <see cref="IMessageTypeResolver"/></typeparam>
 /// <param name="middlewares"></param>
 /// <param name="serializerFactory">A factory to create a <see cref="IMessageSerializer"/></param>
 /// <param name="resolverFactory">A factory to create a <see cref="IMessageTypeResolver"/></param>
 public static IProducerMiddlewareConfigurationBuilder AddSerializer <TSerializer, TResolver>(
     this IProducerMiddlewareConfigurationBuilder middlewares,
     Factory <TSerializer> serializerFactory,
     Factory <TResolver> resolverFactory)
     where TSerializer : class, IMessageSerializer
     where TResolver : class, IMessageTypeResolver
 {
     return(middlewares.Add(
                resolver => new SerializerProducerMiddleware(
                    serializerFactory(resolver),
                    resolverFactory(resolver))));
 }
        /// <summary>
        /// Registers a middleware to serialize messages
        /// </summary>
        /// <typeparam name="TSerializer">A class that implements <see cref="IMessageSerializer"/></typeparam>
        /// <typeparam name="TResolver">A class that implements <see cref="IMessageTypeResolver"/></typeparam>
        public static IProducerMiddlewareConfigurationBuilder AddSerializer <TSerializer, TResolver>(
            this IProducerMiddlewareConfigurationBuilder middlewares)
            where TSerializer : class, IMessageSerializer
            where TResolver : class, IMessageTypeResolver
        {
            middlewares.DependencyConfigurator.AddTransient <TResolver>();
            middlewares.DependencyConfigurator.AddTransient <TSerializer>();

            return(middlewares.Add(
                       resolver => new SerializerProducerMiddleware(
                           resolver.Resolve <TSerializer>(),
                           resolver.Resolve <TResolver>())));
        }
Beispiel #12
0
        /// <summary>
        /// Registers a middleware to serialize messages
        /// </summary>
        /// <typeparam name="TSerializer">A class that implements <see cref="IMessageSerializer"/></typeparam>
        /// <typeparam name="TResolver">A class that implements <see cref="IMessageTypeResolver"/></typeparam>
        /// <param name="producer"></param>
        /// <param name="serializerFactory">A factory to create a <see cref="IMessageSerializer"/></param>
        /// <param name="resolverFactory">A factory to create a <see cref="IMessageTypeResolver"/></param>
        public static IProducerMiddlewareConfigurationBuilder AddSerializer <TSerializer, TResolver>(
            this IProducerMiddlewareConfigurationBuilder producer,
            Factory <TSerializer> serializerFactory,
            Factory <TResolver> resolverFactory)
            where TSerializer : class, IMessageSerializer
            where TResolver : class, IMessageTypeResolver
        {
            producer.DependencyConfigurator.AddSingleton <IMessageSerializer, TSerializer>();
            producer.DependencyConfigurator.AddSingleton <IMessageTypeResolver, TResolver>();
            producer.DependencyConfigurator.AddSingleton <TSerializer>();
            producer.DependencyConfigurator.AddSingleton <TResolver>();

            return(producer.Add(
                       provider => new SerializerProducerMiddleware(
                           serializerFactory(provider),
                           resolverFactory(provider))));
        }
 /// <summary>
 /// Register a middleware to compress the message
 /// </summary>
 /// <typeparam name="T">A class that implements <see cref="IMessageCompressor"/></typeparam>
 public static IProducerMiddlewareConfigurationBuilder AddCompressor <T>(
     this IProducerMiddlewareConfigurationBuilder middlewares)
     where T : class, IMessageCompressor
 {
     return(middlewares.AddCompressor(resolver => resolver.Resolve <T>()));
 }
 /// <summary>
 /// Register a middleware to serialize the message to a fixed type
 /// </summary>
 /// <param name="middlewares"></param>
 /// <typeparam name="TSerializer">A class that implements <see cref="IMessageSerializer"/></typeparam>
 /// <typeparam name="TMessage">The message type</typeparam>
 /// <returns></returns>
 public static IProducerMiddlewareConfigurationBuilder AddSingleTypeSerializer <TMessage, TSerializer>(
     this IProducerMiddlewareConfigurationBuilder middlewares)
     where TSerializer : class, IMessageSerializer
 {
     return(middlewares.AddSerializer <TSerializer, SingleMessageTypeResolver <TMessage> >());
 }
Beispiel #15
0
 /// <summary>
 /// Register a middleware to serialize the message to a fixed type
 /// </summary>
 /// <param name="middlewares">The middleware configuration builder</param>
 /// <typeparam name="TMessage">The message type</typeparam>
 /// <typeparam name="TSerializer">A class that implements <see cref="ISerializer"/></typeparam>
 /// <returns></returns>
 public static IProducerMiddlewareConfigurationBuilder AddSingleTypeSerializer <TMessage, TSerializer>(
     this IProducerMiddlewareConfigurationBuilder middlewares)
     where TSerializer : class, ISerializer
 {
     return(middlewares.AddSingleTypeSerializer <TSerializer>(typeof(TMessage)));
 }
 /// <summary>
 /// Registers a middleware to compress the message
 /// </summary>
 /// <typeparam name="T">A class that implements <see cref="IMessageCompressor"/></typeparam>
 public static IProducerMiddlewareConfigurationBuilder AddCompressor <T>(this IProducerMiddlewareConfigurationBuilder middlewares)
     where T : class, IMessageCompressor
 {
     middlewares.DependencyConfigurator.AddTransient <T>();
     return(middlewares.AddCompressor(resolver => resolver.Resolve <T>()));
 }