Example #1
0
        public RabbitBroadCastService(
            BroadcastServiceOptions options,
            IConnectionFactory connectionFactory,
            BroadcastSubscriptionManager subscriptionManager,
            ILoggerFactory loggerFactory)
        {
            this.options         = options;
            _subscriptionManager = subscriptionManager;
            var queueOptions = new RabbitMessageQueueOptions
            {
                Hostname   = options.Hostname,
                RetryCount = options.RetryCount,
                Exchange   = new ExchangeConfig
                {
                    Name = options.Exchange
                },
                Queue = new QueueConfig
                {
                    Name       = null,
                    Durable    = false,
                    AutoDelete = true,
                    Exclusive  = true
                }
            };

            _queue = new RabbitMessageQueue(connectionFactory,
                                            _subscriptionManager.messageSubscriptionManager,
                                            queueOptions,
                                            loggerFactory.CreateLogger <RabbitMessageQueue>());
        }
Example #2
0
        public static IServiceCollection AddBroadCastService(
            this IServiceCollection services,
            BroadcastServiceOptions options,
            Action <IBroadcastSubscriptionManager>?subcriptionConfig = null,
            Action <ConnectionFactory>?connectionConfig = null)
        {
            services.TryAddSingleton <IBroadcastService>(p =>
            {
                var loggerFactory = p.GetService <ILoggerFactory>();

                var manager = new BroadcastSubscriptionManager(options, p, loggerFactory);
                subcriptionConfig?.Invoke(manager);

                var factory = new ConnectionFactory()
                {
                    HostName = options.Hostname
                };
                connectionConfig?.Invoke(factory);

                return(new RabbitBroadCastService(options, factory, manager, loggerFactory));
            });
            return(services);
        }