Esempio n. 1
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="connectionObject"> 连接对象 </param>
        /// <param name="channel">          管道 </param>
        /// <param name="logger">           日志对象 </param>
        public ChannelObject(ConnectionObject connectionObject, IModel channel, ILogger <ChannelObject> logger)
        {
            this.channel          = channel;
            this.connectionObject = connectionObject;
            messages    = new List <PushMessageObject>();
            this.logger = logger ?? throw new ArgumentNullException(nameof(logger));

            persistentProperties            = channel.CreateBasicProperties();
            persistentProperties.Persistent = true;

            unPersistentProperties            = channel.CreateBasicProperties();
            unPersistentProperties.Persistent = false;

            //定义交换机
            channel.ExchangeDeclare(connectionObject.RabbitMQOptions.ExchangeName, "topic", true, false);
            BuilderSendAction();
        }
Esempio n. 2
0
        public ChannelObject Create()
        {
            if (connectionObjects.Count < rabbitMQOptions.ConnectionPoolSize)
            {
                var connection       = connectionFactory.CreateConnection(rabbitMQOptions.EndPoints);
                var connectionObject = new ConnectionObject(connection, rabbitMQOptions, consumerOptions, producerOptions, loggerFactory);
                connectionObjects.Add(connectionObject);
                return(connectionObject.GetChannel());
            }

            if (++counter >= connectionObjects.Count)
            {
                counter = 0;
            }

            return(connectionObjects[counter].GetChannel());
        }