Exemple #1
0
        public void Start(ISenderCallback callback)
        {
            _callback = callback;
            _grouper  = new ActionBlock <Envelope[]>(_ => groupMessages(_));
            _outgoing = new BatchingBlock <Envelope>(200, _grouper);

            _sender = new ActionBlock <OutgoingMessageBatch>(sendBatch, new ExecutionDataflowBlockOptions
            {
                MaxDegreeOfParallelism = 5
            });
        }
Exemple #2
0
        public MartenRetries(IDocumentStore store, EnvelopeTables tables, CompositeTransportLogger logger, BusSettings settings)
        {
            _store    = store;
            _tables   = tables;
            _logger   = logger;
            _settings = settings;

            _deleteIncoming         = new ActionBlock <Envelope[]>(deleteIncoming);
            _deleteIncomingBatching = new BatchingBlock <Envelope>(250.Milliseconds(), _deleteIncoming, settings.Cancellation);

            _deleteOutgoing         = new ActionBlock <Envelope[]>(deleteOutgoing);
            _deleteOutgoingBatching = new BatchingBlock <Envelope>(250.Milliseconds(), _deleteOutgoing, settings.Cancellation);

            _logErrorReport         = new ActionBlock <ErrorReport[]>(logErrorReports);
            _logErrorReportBatching = new BatchingBlock <ErrorReport>(250.Milliseconds(), _logErrorReport, settings.Cancellation);

            _scheduleIncoming         = new ActionBlock <Envelope[]>(scheduleIncoming);
            _scheduleIncomingBatching = new BatchingBlock <Envelope>(250.Milliseconds(), _scheduleIncoming, settings.Cancellation);
        }
Exemple #3
0
        public void Start(ISenderCallback callback)
        {
            _callback = callback;

            _sender = new ActionBlock <OutgoingMessageBatch>(SendBatch, new ExecutionDataflowBlockOptions
            {
                MaxDegreeOfParallelism = 1,
                CancellationToken      = _cancellation
            });

            _serializing = new ActionBlock <Envelope>(e =>
            {
                try
                {
                    e.EnsureData();
                    _batching.Post(e);
                }
                catch (Exception ex)
                {
                    _logger.LogException(ex, message: $"Error while trying to serialize envelope {e}");
                }
            },
                                                      new ExecutionDataflowBlockOptions
            {
                CancellationToken = _cancellation
            });


            _batchWriting = new TransformBlock <Envelope[], OutgoingMessageBatch>(
                envelopes =>
            {
                var batch = new OutgoingMessageBatch(Destination, envelopes);
                _queued  += batch.Messages.Count;
                return(batch);
            });

            _batchWriting.LinkTo(_sender);

            _batching = new BatchingBlock <Envelope>(200, _batchWriting, _cancellation);
        }
Exemple #4
0
        public EnvelopeRetries(IEnvelopePersistor persistor, ITransportLogger logger, JasperOptions settings)
        {
            _persistor = persistor;

            _logger   = logger;
            _settings = settings;

            _deleteIncoming         = new ActionBlock <Envelope[]>(deleteIncoming);
            _deleteIncomingBatching =
                new BatchingBlock <Envelope>(100.Milliseconds(), _deleteIncoming, settings.Cancellation);

            _deleteOutgoing         = new ActionBlock <Envelope[]>(deleteOutgoing);
            _deleteOutgoingBatching =
                new BatchingBlock <Envelope>(100.Milliseconds(), _deleteOutgoing, settings.Cancellation);

            _logErrorReport         = new ActionBlock <ErrorReport[]>(logErrorReports);
            _logErrorReportBatching =
                new BatchingBlock <ErrorReport>(100.Milliseconds(), _logErrorReport, settings.Cancellation);

            _scheduleIncoming         = new ActionBlock <Envelope[]>(scheduleIncoming);
            _scheduleIncomingBatching =
                new BatchingBlock <Envelope>(100.Milliseconds(), _scheduleIncoming, settings.Cancellation);
        }
Exemple #5
0
        public BatchedSender(Uri destination, ISenderProtocol protocol, CancellationToken cancellation, ITransportLogger logger)
        {
            Destination   = destination;
            _protocol     = protocol;
            _cancellation = cancellation;
            _logger       = logger;

            _sender = new ActionBlock <OutgoingMessageBatch>(SendBatch, new ExecutionDataflowBlockOptions
            {
                MaxDegreeOfParallelism = 1,
                CancellationToken      = _cancellation,
                BoundedCapacity        = DataflowBlockOptions.Unbounded
            });

            _sender.Completion.ContinueWith(x =>
            {
                if (x.IsFaulted)
                {
                    _logger.LogException(x.Exception);
                }
            }, _cancellation);

            _serializing = new ActionBlock <Envelope>(async e =>
            {
                try
                {
                    await _batching.SendAsync(e);
                }
                catch (Exception ex)
                {
                    _logger.LogException(ex, message: $"Error while trying to serialize envelope {e}");
                }
            },
                                                      new ExecutionDataflowBlockOptions
            {
                CancellationToken = _cancellation,
                BoundedCapacity   = DataflowBlockOptions.Unbounded
            });


            _serializing.Completion.ContinueWith(x =>
            {
                if (x.IsFaulted)
                {
                    _logger.LogException(x.Exception);
                }
            }, _cancellation);


            _batchWriting = new TransformBlock <Envelope[], OutgoingMessageBatch>(
                envelopes =>
            {
                var batch = new OutgoingMessageBatch(Destination, envelopes);
                _queued  += batch.Messages.Count;
                return(batch);
            },
                new ExecutionDataflowBlockOptions
            {
                BoundedCapacity = DataflowBlockOptions.Unbounded, MaxDegreeOfParallelism = 10, CancellationToken = _cancellation
            });

            _batchWriting.Completion.ContinueWith(x =>
            {
                if (x.IsFaulted)
                {
                    _logger.LogException(x.Exception);
                }
            }, _cancellation);

            _batchWriting.LinkTo(_sender);

            _batching = new BatchingBlock <Envelope>(200, _batchWriting, _cancellation);
            _batching.Completion.ContinueWith(x =>
            {
                if (x.IsFaulted)
                {
                    _logger.LogException(x.Exception);
                }
            }, _cancellation);
        }
Exemple #6
0
        public void Start(ISenderCallback callback)
        {
            _callback = callback;

            _sender = new ActionBlock <OutgoingMessageBatch>(SendBatch, new ExecutionDataflowBlockOptions
            {
                MaxDegreeOfParallelism = 1,
                CancellationToken      = _cancellation,
                BoundedCapacity        = DataflowBlockOptions.Unbounded
            });

            _sender.Completion.ContinueWith(x =>
            {
                if (x.IsFaulted)
                {
                    // TODO -- need to restart things!!!
                    _logger.LogException(x.Exception);
                }
            }, _cancellation);

            _serializing = new ActionBlock <Envelope>(async e =>
            {
                try
                {
                    e.EnsureData();
                    await _batching.SendAsync(e);
                }
                catch (Exception ex)
                {
                    _logger.LogException(ex, message: $"Error while trying to serialize envelope {e}");
                }
            },
                                                      new ExecutionDataflowBlockOptions
            {
                CancellationToken = _cancellation,
                BoundedCapacity   = DataflowBlockOptions.Unbounded
            });


            _serializing.Completion.ContinueWith(x =>
            {
                if (x.IsFaulted)
                {
                    // TODO -- need to restart things!!!
                    _logger.LogException(x.Exception);
                }
            }, _cancellation);


            _batchWriting = new TransformBlock <Envelope[], OutgoingMessageBatch>(
                envelopes =>
            {
                var batch = new OutgoingMessageBatch(Destination, envelopes);
                _queued  += batch.Messages.Count;
                return(batch);
            }, new ExecutionDataflowBlockOptions {
                BoundedCapacity = DataflowBlockOptions.Unbounded, MaxDegreeOfParallelism = 10
            });

            _batchWriting.Completion.ContinueWith(x =>
            {
                if (x.IsFaulted)
                {
                    // TODO -- need to restart things!!!
                    _logger.LogException(x.Exception);
                }
            }, _cancellation);

            _batchWriting.LinkTo(_sender);

            _batching = new BatchingBlock <Envelope>(200, _batchWriting, _cancellation);
            _batching.Completion.ContinueWith(x =>
            {
                if (x.IsFaulted)
                {
                    // TODO -- need to restart things!!!
                    _logger.LogException(x.Exception);
                }
            }, _cancellation);
        }