Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        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();
        }
Exemplo n.º 4
0
        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;
            }
        }