Exemple #1
0
        public void Setup(PeriodicBatchingConfiguration <TEvent> config)
        {
            if (this.IsAlreadyInitialized)
            {
                throw new InvalidOperationException("Setup cannot be called two times");
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            config.Validate();

            this.PeriodicBatchingConfiguration = config;
            this.Status         = new BatchedConnectionStatus <TEvent>(config);
            this.BatchingFunc   = config.BatchingFunc;
            this.BatchSizeLimit = config.BatchSizeLimit;
            this.Queue          = new BoundedConcurrentQueue <TEvent>();
            this.Timer          = new PortableTimer(cancel => OnTick());
        }
Exemple #2
0
        static void Main(string[] args)
        {
            var config = new PeriodicBatchingConfiguration <SomeEvent>
            {
                BatchSizeLimit = 5,
                FailuresBeforeDroppingBatch = 3,
                FailuresBeforeDroppingQueue = 10,
                BatchingFunc          = ExecuteMethod,
                SingleFailureCallback = SingleFailure,
                DropBatchCallback     = DropBatch,
                DropQueueCallback     = DropQueue,
                Period = TimeSpan.FromSeconds(5),
                MinimumBackoffPeriod   = TimeSpan.FromSeconds(3),
                MaximumBackoffInterval = TimeSpan.FromMinutes(5),
            };

            IPeriodicBatching <SomeEvent> periodicBatching = new PeriodicBatching <SomeEvent>(config);

            int    i       = 0;
            int    max     = 100;
            string command = "error";

            while (true)
            {
                if (i < max)
                {
                    periodicBatching.Add(new SomeEvent {
                        Prop1 = i.ToString(), Prop2 = command
                    });
                    Thread.Sleep(100);
                    i++;
                }
                else
                {
                    Thread.Sleep(5000);
                }
            }
        }
 public BatchedConnectionStatus(PeriodicBatchingConfiguration <TEvent> config)
 {
     this.PeriodicBatchingConfiguration = config;
 }
Exemple #4
0
 public PeriodicBatching(PeriodicBatchingConfiguration <TEvent> config)
 {
     this.Setup(config);
 }