コード例 #1
0
ファイル: RouterMQ.cs プロジェクト: Aqmic/Dcp.Lib
 public override bool CreateMQ(IList <string> routeKeyList)
 {
     this._channel = _connection.CreateModel();
     IModelExensions.ExchangeDeclare(this._channel, base.MQConfig.Exchange, base.MQConfig.MsgSendType.ToExchangeType(), base.MQConfig.IsDurable, base.MQConfig.AutoDelete, null);
     BindConfig(this._queue, routeKeyList);
     return(true);
 }
コード例 #2
0
        public IModel CreateProducerChannelByConfig(ProducerConfigInfo producerConfigInfo)
        {
            IModel channel = this.CreateChannel();

            IModelExensions.ExchangeDeclare(channel, producerConfigInfo.ExchangeName, producerConfigInfo.ExchangeTypeCode, producerConfigInfo.ExchangeDurable, false, (IDictionary <string, object>)null);
            return(channel);
        }
コード例 #3
0
ファイル: SimpleMQ.cs プロジェクト: Aqmic/Dcp.Lib
        public override void Send(MQMessage mQMessage, Action <MQMessage> callBackAction)
        {
            IBasicProperties properties = this.Channel.CreateBasicProperties();

            if (mQMessage.Response != null)
            {
                properties.ReplyTo = mQMessage.Response.ResponseQueue;
            }
            properties.DeliveryMode    = base.MQConfig.IsDurable ? ((byte)2) : ((byte)1);
            properties.ContentEncoding = this._encoding.EncodingName;
            if (!string.IsNullOrEmpty(mQMessage.MsgId))
            {
                properties.MessageId = mQMessage.MsgId;
            }
            if (!string.IsNullOrEmpty(mQMessage.Label))
            {
                properties.CorrelationId = mQMessage.Label;
            }
            IModelExensions.BasicPublish(this.Channel, null, null, properties, mQMessage.ToData());
            if ((mQMessage.Response != null) && (this.Consumer == null))
            {
                this.Consumer = new EventingBasicConsumer(this.Channel);
                IModelExensions.BasicConsume(this.Channel, mQMessage.Response.ResponseQueue, false, this.Consumer);
                if (callBackAction != null)
                {
                    this.Consumer.Received += (obj, ee) =>
                    {
                        if (callBackAction != null)
                        {
                            this.CallBack(obj, ee, callBackAction);
                        }
                    };
                }
            }
        }
コード例 #4
0
ファイル: SimpleMQ.cs プロジェクト: Aqmic/Dcp.Lib
 public override bool CreateMQ(IList <string> routeKeyList)
 {
     this._channel = _connection.CreateModel();
     this._channel.QueueDeclare(this._queue, base.MQConfig.IsDurable, false, base.MQConfig.AutoDelete, null);
     IModelExensions.QueueBind(this._channel, this._queue, null, null, null);
     return(true);
 }
コード例 #5
0
 public override void BindConfig(string queue, IList <string> routeKeyList)
 {
     this.Channel.QueueDeclare(queue, base.MQConfig.IsDurable, false, base.MQConfig.AutoDelete, null);
     foreach (var routeKey in routeKeyList)
     {
         IModelExensions.QueueBind(this.Channel, queue, base.MQConfig.Exchange, routeKey, null);
     }
 }
コード例 #6
0
ファイル: RouterMQ.cs プロジェクト: Aqmic/Dcp.Lib
        public override void Send(byte[] body, string label = null)
        {
            IBasicProperties properties = this.Channel.CreateBasicProperties();

            properties.DeliveryMode    = base.MQConfig.IsDurable ? ((byte)2) : ((byte)1);
            properties.ContentEncoding = this._encoding.EncodingName;
            if (label != null)
            {
                properties.CorrelationId = label;
            }
            IModelExensions.BasicPublish(this.Channel, base.MQConfig.Exchange, base.MQConfig.ConsumerID, properties, body);
        }
コード例 #7
0
ファイル: RouterMQ.cs プロジェクト: Aqmic/Dcp.Lib
        public override void ReceiveMQ(Action <MQMessage> action)
        {
            EventingBasicConsumer consumer = new EventingBasicConsumer(this.Channel);

            consumer.Received += (ch, ea) =>
            {
                this.CallBack(ch, ea, action);
            };
            ///不全部给一次给一条(能者多劳,可以快速取第二条)
            this.Channel.BasicQos(0, 1, false);
            string str = IModelExensions.BasicConsume(this.Channel, this._queue, false, consumer);
        }
コード例 #8
0
ファイル: RouterMQ.cs プロジェクト: Aqmic/Dcp.Lib
        public override void ReceiveBinary(Action <byte[]> action)
        {
            EventingBasicConsumer consumer = new EventingBasicConsumer(this.Channel);

            consumer.Received += (ch, ea) =>
            {
                try
                {
                    action(ea.Body);
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                }
                finally
                {
                    this.Channel.BasicAck(ea.DeliveryTag, false);
                }
            };
            this.Channel.BasicQos(0, 1, false);
            string str = IModelExensions.BasicConsume(this.Channel, this._queue, false, consumer);
        }
コード例 #9
0
ファイル: SimpleMQ.cs プロジェクト: Aqmic/Dcp.Lib
 public override void BindConfig(string queue, string routeKey = null)
 {
     this.Channel.QueueDeclare(queue, base.MQConfig.IsDurable, false, base.MQConfig.AutoDelete, null);
     IModelExensions.QueueBind(this.Channel, queue, null, null, null);
 }