protected virtual void Build() { ProducerSettingsByMessageType = new Dictionary <Type, ProducerSettings>(); foreach (var producerSettings in Settings.Producers) { if (ProducerSettingsByMessageType.ContainsKey(producerSettings.MessageType)) { throw new ConfigurationMessageBusException($"The produced message type '{producerSettings.MessageType}' was declared more than once (check the {nameof(MessageBusBuilder.Produce)} configuration)"); } ProducerSettingsByMessageType.Add(producerSettings.MessageType, producerSettings); } PendingRequestStore = new InMemoryPendingRequestStore(); PendingRequestManager = new PendingRequestManager(PendingRequestStore, () => CurrentTime, TimeSpan.FromSeconds(1), LoggerFactory, request => { // Execute the event hook try { (Settings.RequestResponse.OnMessageExpired ?? Settings.OnMessageExpired)?.Invoke(this, Settings.RequestResponse, request, null); } catch (Exception eh) { HookFailed(_logger, eh, nameof(IConsumerEvents.OnMessageExpired)); } }); PendingRequestManager.Start(); }
protected MessageBusBase(MessageBusSettings settings) { AssertSettings(settings); Settings = settings; PublisherSettingsByMessageType = settings.Publishers.ToDictionary(x => x.MessageType); PendingRequestStore = new InMemoryPendingRequestStore(); PendingRequestManager = new PendingRequestManager(PendingRequestStore, () => CurrentTime, TimeSpan.FromSeconds(1), request => { // Execute the event hook // ToDo: sort out the ConsumerSettings arg for req/resp, for now pass null (Settings.RequestResponse.OnMessageExpired ?? Settings.OnMessageExpired)?.Invoke(null, request); }); PendingRequestManager.Start(); }
protected virtual void Build() { ProducerSettingsByMessageType = new Dictionary <Type, ProducerSettings>(); foreach (var producerSettings in Settings.Producers) { if (ProducerSettingsByMessageType.ContainsKey(producerSettings.MessageType)) { throw new ConfigurationMessageBusException($"The produced message type '{producerSettings.MessageType}' was declared more than once (check the {nameof(MessageBusBuilder.Produce)} configuration)"); } ProducerSettingsByMessageType.Add(producerSettings.MessageType, producerSettings); } PendingRequestStore = new InMemoryPendingRequestStore(); PendingRequestManager = new PendingRequestManager(PendingRequestStore, () => CurrentTime, TimeSpan.FromSeconds(1), request => { // Execute the event hook // ToDo: sort out the ConsumerSettings arg for req/resp, for now pass null (Settings.RequestResponse.OnMessageExpired ?? Settings.OnMessageExpired)?.Invoke(null, request); }); PendingRequestManager.Start(); }
protected virtual void Dispose(bool disposing) { if (IsDisposed) { return; } IsDisposing = true; try { if (disposing) { _cancellationTokenSource.Cancel(); _cancellationTokenSource.Dispose(); PendingRequestManager.Dispose(); } } finally { IsDisposing = false; IsDisposed = true; } }