Пример #1
0
        public Task StartAsync()
        {
            return(Task.Run(InitCore));

            void InitCore()
            {
                _connection = _connectionManager.CreateConnection();
                _senders    = _claptrapDesignStore
                              .Where(x => !x.IsMinion())
                              .ToDictionary(x => x.ClaptrapTypeCode, x =>
                {
                    var exchangeName = TopicHelper.GetExchangeName(x.ClaptrapTypeCode);
                    var topics       = x.EventHandlerDesigns
                                       .ToDictionary(a => a.Key, a => TopicHelper.GetRouteKey(x.ClaptrapTypeCode, a.Key));
                    using var model = _connection.CreateModel();
                    model.ExchangeDeclare(exchangeName, ExchangeType.Topic);
                    var mqSender = _mqSenderFactory.Invoke(exchangeName, topics, _connection);
                    return(mqSender);
                });
            }
        }
Пример #2
0
        public Task StartAsync()
        {
            return(Task.Run(StartCore));

            void StartCore()
            {
                var connection = _connectionManager.CreateConnection();

                _consumers = _claptrapDesignStore
                             .Where(x => x.IsMinion())
                             .ToDictionary(x => x.ClaptrapTypeCode,
                                           x =>
                {
                    var masterDesign = x.ClaptrapMasterDesign;
                    var model        = connection.CreateModel();
                    var exchangeName = TopicHelper.GetExchangeName(masterDesign.ClaptrapTypeCode);
                    var subscribeKey = TopicHelper.GetSubscribeKey(masterDesign.ClaptrapTypeCode);
                    var queueName    = TopicHelper.GetQueueName(x.ClaptrapTypeCode);
                    model.ExchangeDeclare(exchangeName, ExchangeType.Topic);
                    _logger.LogTrace("declare exchange : {exchangeName}", exchangeName);
                    model.QueueDeclare(queueName,
                                       false,
                                       false,
                                       false,
                                       null);
                    _logger.LogTrace("declare queue : {queueName}", queueName);
                    model.QueueBind(queueName, exchangeName, subscribeKey, null);
                    _logger.LogTrace("bind queue : {queueName} to {exchangeName}", queueName, exchangeName);
                    var consumer       = new AsyncEventingBasicConsumer(model);
                    consumer.Received += (sender, @event) =>
                                         AsyncEventingBasicConsumerOnReceived(sender, @event, x);
                    model.BasicConsume(queueName, false, consumer);
                    return(model);
                });
            }
        }