/// <summary> /// Initializes a new <see cref="MessageJournalConsumer"/> with the specified configuration /// and services /// </summary> /// <remarks> /// Message journal consumers created with this constructor use an internal <see cref="Bus"/> /// instance based on the <see cref="LoopbackTransportService"/> and <see cref="VirtualMessageQueueingService"/> /// to minimize overhead of message processing. /// </remarks> /// <param name="configuration">The bus configuration</param> /// <param name="options">(Optional) Options to customize the behavior of the message journal consumer</param> /// <exception cref="ArgumentNullException">Thrown if any of the parameters are <c>null</c></exception> public MessageJournalConsumer(IPlatibusConfiguration configuration, MessageJournalConsumerOptions options) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } _diagnosticService = configuration.DiagnosticService; _messageJournal = configuration.MessageJournal ?? throw new ConfigurationErrorsException("Message journal is required"); _bus = InitBus(configuration); var myOptions = options ?? new MessageJournalConsumerOptions(); _filter = myOptions.Filter; _batchSize = myOptions.BatchSize > 0 ? myOptions.BatchSize : MessageJournalConsumerOptions.DefaultBatchSize; _rethrowExceptions = myOptions.RethrowExceptions; _haltAtEndOfJournal = myOptions.HaltAtEndOfJournal; _pollingInterval = myOptions.PollingInterval > TimeSpan.Zero ? myOptions.PollingInterval : MessageJournalConsumerOptions.DefaultPollingInterval; _progress = myOptions.Progress; }
/// <summary> /// Initializes a new <see cref="MessageJournalConsumer"/> with the specified configuration /// and services /// </summary> /// <param name="bus">A configured and initialized bus instance that will be used to handle /// incoming messages</param> /// <param name="messageJournal">The message journal from which entries will be consumed</param> /// <param name="options">(Optional) Options to customize the behavior of the message journal consumer</param> /// <exception cref="ArgumentNullException">Thrown if any of the parameters are <c>null</c></exception> public MessageJournalConsumer(IBus bus, IMessageJournal messageJournal, MessageJournalConsumerOptions options) { if (bus == null) { throw new ArgumentNullException(nameof(bus)); } _diagnosticService = DiagnosticService.DefaultInstance; _messageJournal = messageJournal ?? throw new ConfigurationErrorsException("Message journal is required"); _bus = Task.FromResult(bus); var myOptions = options ?? new MessageJournalConsumerOptions(); _filter = myOptions.Filter; _batchSize = myOptions.BatchSize > 0 ? myOptions.BatchSize : MessageJournalConsumerOptions.DefaultBatchSize; _rethrowExceptions = myOptions.RethrowExceptions; _haltAtEndOfJournal = myOptions.HaltAtEndOfJournal; _pollingInterval = myOptions.PollingInterval > TimeSpan.Zero ? myOptions.PollingInterval : MessageJournalConsumerOptions.DefaultPollingInterval; _progress = myOptions.Progress; }