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 }); }
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); }
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); }
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); }
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); }
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); }