internal SubscribeHostedService(
            ConsummerSettings consummerSettings,
            IOptionsSnapshot <SubscribeSettings <TMessage> > subscribeSettings,
            string topicName)
        {
            _consummerSettings = consummerSettings;
            _subscribeSettings = subscribeSettings.Get(topicName);
            _topicName         = topicName;

            _consummerSettings.Consumer.IncomeMessage       += Consumer_IncomeMessage;
            _consummerSettings.Consumer.ErrorProcessMessage += Consumer_ErrorProcessMessage;
        }
Пример #2
0
        public ISubscriber Subscribe <TMessage>(string topicName, Action <SubscribeSettings <TMessage> > options)
        {
            _services.Configure <SubscribeSettings <TMessage> >(topicName, options);

            _services.AddSingleton <IHostedService, SubscribeHostedService <TMessage> >(provider =>
            {
                var subscribeOptions = provider.GetRequiredService <IOptionsSnapshot <SubscribeSettings <TMessage> > >();
                var consummerOptions = new ConsummerSettings();
                _consummerSettingsAction(consummerOptions);

                return(new SubscribeHostedService <TMessage>(
                           consummerOptions,
                           subscribeOptions,
                           topicName
                           ));
            });
            return(this);
        }