Пример #1
0
        /// <summary>
        /// Specify a concurrency limit for tasks executing through the filter. No more than the specified
        /// number of tasks will be allowed to execute concurrently.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="configurator"></param>
        /// <param name="partitioner">An existing partitioner that is shared</param>
        /// <param name="keyProvider">Provides the key from the message</param>
        public static void UsePartitioner <T>(this IPipeConfigurator <T> configurator, IPartitioner partitioner, Func <T, long> keyProvider)
            where T : class, PipeContext
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }
            if (partitioner == null)
            {
                throw new ArgumentNullException(nameof(partitioner));
            }
            if (keyProvider == null)
            {
                throw new ArgumentNullException(nameof(keyProvider));
            }

            PartitionKeyProvider <T> provider = context =>
            {
                var key = keyProvider(context);
                return(BitConverter.GetBytes(key));
            };

            var specification = new PartitionerPipeSpecification <T>(provider, partitioner);

            configurator.AddPipeSpecification(specification);
        }
        /// <summary>
        /// Specify a concurrency limit for tasks executing through the filter. No more than the specified
        /// number of tasks will be allowed to execute concurrently.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="configurator"></param>
        /// <param name="partitioner">An existing partitioner that is shared</param>
        /// <param name="keyProvider">Provides the key from the message</param>
        public static void UsePartitioner <T>(this IConsumePipeConfigurator configurator, IPartitioner partitioner, Func <ConsumeContext <T>, Guid> keyProvider)
            where T : class
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }
            if (partitioner == null)
            {
                throw new ArgumentNullException(nameof(partitioner));
            }
            if (keyProvider == null)
            {
                throw new ArgumentNullException(nameof(keyProvider));
            }

            byte[] Provider(ConsumeContext <T> context)
            {
                return(keyProvider(context).ToByteArray());
            }

            var specification = new PartitionerPipeSpecification <ConsumeContext <T> >(Provider, partitioner);

            configurator.AddPipeSpecification(specification);
        }
Пример #3
0
        /// <summary>
        /// Specify a concurrency limit for tasks executing through the filter. No more than the specified
        /// number of tasks will be allowed to execute concurrently.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="configurator"></param>
        /// <param name="partitioner">An existing partitioner that is shared</param>
        /// <param name="keyProvider">Provides the key from the message</param>
        /// <param name="encoding"></param>
        public static void UsePartitioner <T>(this IPipeConfigurator <T> configurator, IPartitioner partitioner, Func <T, string> keyProvider,
                                              Encoding encoding = null)
            where T : class, PipeContext
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }
            if (partitioner == null)
            {
                throw new ArgumentNullException(nameof(partitioner));
            }
            if (keyProvider == null)
            {
                throw new ArgumentNullException(nameof(keyProvider));
            }

            var textEncoding = encoding ?? Encoding.UTF8;

            PartitionKeyProvider <T> provider = context =>
            {
                var key = keyProvider(context) ?? "";
                return(textEncoding.GetBytes(key));
            };

            var specification = new PartitionerPipeSpecification <T>(provider, partitioner);

            configurator.AddPipeSpecification(specification);
        }
Пример #4
0
        /// <summary>
        /// Specify a concurrency limit for tasks executing through the filter. No more than the specified
        /// number of tasks will be allowed to execute concurrently.
        /// </summary>
        /// <typeparam name="TActivity"></typeparam>
        /// <typeparam name="TLog"></typeparam>
        /// <param name="configurator"></param>
        /// <param name="partitionCount">The number of partitions to use when distributing message delivery</param>
        /// <param name="keyProvider">Provides the key from the message</param>
        /// <param name="encoding">The text encoding to use to convert the string to byte[] (defaults to UTF8)</param>
        public static void UsePartitioner <TActivity, TLog>(this IPipeConfigurator <CompensateActivityContext <TActivity, TLog> > configurator,
                                                            int partitionCount, Func <CompensateActivityContext <TActivity, TLog>, string> keyProvider, Encoding encoding = null)
            where TActivity : class, CompensateActivity <TLog>
            where TLog : class
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }
            if (keyProvider == null)
            {
                throw new ArgumentNullException(nameof(keyProvider));
            }

            var textEncoding = encoding ?? Encoding.UTF8;

            PartitionKeyProvider <CompensateActivityContext <TActivity, TLog> > provider = context =>
            {
                var key = keyProvider(context) ?? "";
                return(textEncoding.GetBytes(key));
            };

            var specification = new PartitionerPipeSpecification <CompensateActivityContext <TActivity, TLog> >(provider, partitionCount);

            configurator.AddPipeSpecification(specification);
        }
        /// <summary>
        /// Specify a concurrency limit for tasks executing through the filter. No more than the specified
        /// number of tasks will be allowed to execute concurrently.
        /// </summary>
        /// <typeparam name="TActivity"></typeparam>
        /// <typeparam name="TLog"></typeparam>
        /// <param name="configurator"></param>
        /// <param name="partitioner">An existing partitioner to share</param>
        /// <param name="keyProvider">Provides the key from the message</param>
        public static void UsePartitioner <TActivity, TLog>(this IPipeConfigurator <CompensateActivityContext <TActivity, TLog> > configurator,
                                                            IPartitioner partitioner, Func <CompensateActivityContext <TActivity, TLog>, Guid> keyProvider)
            where TActivity : class, ICompensateActivity <TLog>
            where TLog : class
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }
            if (partitioner == null)
            {
                throw new ArgumentNullException(nameof(partitioner));
            }
            if (keyProvider == null)
            {
                throw new ArgumentNullException(nameof(keyProvider));
            }

            byte[] PartitionKeyProvider(CompensateActivityContext <TActivity, TLog> context)
            {
                return(keyProvider(context).ToByteArray());
            }

            var specification = new PartitionerPipeSpecification <CompensateActivityContext <TActivity, TLog> >(PartitionKeyProvider, partitioner);

            configurator.AddPipeSpecification(specification);
        }
Пример #6
0
        /// <summary>
        /// Specify a concurrency limit for tasks executing through the filter. No more than the specified
        /// number of tasks will be allowed to execute concurrently.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="configurator"></param>
        /// <param name="partitioner">An existing partitioner that is shared</param>
        /// <param name="keyProvider">Provides the key from the message</param>
        public static void UsePartitioner <T>(this IPipeConfigurator <T> configurator, IPartitioner partitioner, Func <T, byte[]> keyProvider)
            where T : class, PipeContext
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }
            if (partitioner == null)
            {
                throw new ArgumentNullException(nameof(partitioner));
            }
            if (keyProvider == null)
            {
                throw new ArgumentNullException(nameof(keyProvider));
            }

            byte[] Provider(T context)
            {
                return(keyProvider(context));
            }

            var specification = new PartitionerPipeSpecification <T>(Provider, partitioner);

            configurator.AddPipeSpecification(specification);
        }
Пример #7
0
        /// <summary>
        /// Specify a concurrency limit for tasks executing through the filter. No more than the specified
        /// number of tasks will be allowed to execute concurrently.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="configurator"></param>
        /// <param name="partitionCount">The number of partitions to use when distributing message delivery</param>
        /// <param name="keyProvider">Provides the key from the message</param>
        public static void UsePartitioner <T>(this IPipeConfigurator <T> configurator, int partitionCount, Func <T, Guid> keyProvider)
            where T : class, PipeContext
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }
            if (keyProvider == null)
            {
                throw new ArgumentNullException(nameof(keyProvider));
            }

            PartitionKeyProvider <T> provider = context => keyProvider(context).ToByteArray();

            var specification = new PartitionerPipeSpecification <T>(provider, partitionCount);

            configurator.AddPipeSpecification(specification);
        }
Пример #8
0
        /// <summary>
        /// Specify a concurrency limit for tasks executing through the filter. No more than the specified
        /// number of tasks will be allowed to execute concurrently.
        /// </summary>
        /// <typeparam name="TActivity"></typeparam>
        /// <typeparam name="TLog"></typeparam>
        /// <param name="configurator"></param>
        /// <param name="partitionCount">The number of partitions to use when distributing message delivery</param>
        /// <param name="keyProvider">Provides the key from the message</param>
        public static void UsePartitioner <TActivity, TLog>(this IPipeConfigurator <CompensateActivityContext <TActivity, TLog> > configurator,
                                                            int partitionCount, Func <CompensateActivityContext <TActivity, TLog>, Guid> keyProvider)
            where TActivity : class, CompensateActivity <TLog>
            where TLog : class
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }
            if (keyProvider == null)
            {
                throw new ArgumentNullException(nameof(keyProvider));
            }

            PartitionKeyProvider <CompensateActivityContext <TActivity, TLog> > provider = context => keyProvider(context).ToByteArray();

            var specification = new PartitionerPipeSpecification <CompensateActivityContext <TActivity, TLog> >(provider, partitionCount);

            configurator.AddPipeSpecification(specification);
        }
Пример #9
0
        /// <summary>
        /// Specify a concurrency limit for tasks executing through the filter. No more than the specified
        /// number of tasks will be allowed to execute concurrently.
        /// </summary>
        /// <typeparam name="TActivity"></typeparam>
        /// <typeparam name="TArguments"></typeparam>
        /// <param name="configurator"></param>
        /// <param name="partitioner">An existing partitioner to share</param>
        /// <param name="keyProvider">Provides the key from the message</param>
        public static void UsePartitioner <TActivity, TArguments>(this IPipeConfigurator <ExecuteActivityContext <TActivity, TArguments> > configurator,
                                                                  IPartitioner partitioner, Func <ExecuteActivityContext <TActivity, TArguments>, Guid> keyProvider)
            where TActivity : class, ExecuteActivity <TArguments>
            where TArguments : class
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }
            if (partitioner == null)
            {
                throw new ArgumentNullException(nameof(partitioner));
            }
            if (keyProvider == null)
            {
                throw new ArgumentNullException(nameof(keyProvider));
            }

            PartitionKeyProvider <ExecuteActivityContext <TActivity, TArguments> > provider = context => keyProvider(context).ToByteArray();

            var specification = new PartitionerPipeSpecification <ExecuteActivityContext <TActivity, TArguments> >(provider, partitioner);

            configurator.AddPipeSpecification(specification);
        }