Exemple #1
0
        public void Send(MQMessage mQMessage)
        {
            object obj2 = this._LockObj;

            lock (obj2)
            {
                if (mQMessage.Response == null)
                {
                    MQMsgResponse response1 = new MQMsgResponse
                    {
                        Exchange = this.MQConfig.Exchange
                    };
                    mQMessage.Response = response1;
                }
                mQMessage.Response.ResponseQueue    = this._mQMsgResponse.ResponseQueue;
                mQMessage.Response.ResponseRouteKey = this._mQMsgResponse.ResponseRouteKey;
                if (mQMessage.Request == null)
                {
                    mQMessage.Request = this._mQMsgRequest;
                }
                if (string.IsNullOrEmpty(mQMessage.Label))
                {
                    mQMessage.Label = this.ApplicationId;
                }
                this.MsgQueue.BindConfig(this._mQMsgResponse.ResponseQueue, this._mQMsgResponse.ResponseRouteKey);
                this.MsgQueue.Send(mQMessage, (msg) =>
                {
                    DataItem <MQMessage> command = new DataItem <MQMessage>();
                    command.Data         = msg;
                    command.ReceivedTime = DateTime.Now;
                    this._lstDeviceDataQueue.Push(command);
                    Task.Factory.StartNew(() =>
                    {
                        if (this.ReciveMsgedEvent != null)
                        {
                            this.ReciveMsgedEvent(msg);
                        }
                    });
                });
            }
        }
Exemple #2
0
        public RpcClient(DistributedMQConfig distributedMQConfig, MQMsgRequest mQMsgRequest = null, string applicationId = null) : base(distributedMQConfig)
        {
            this.ApplicationId = applicationId;
            this.MQConfig      = distributedMQConfig;
            this.MsgQueue      = MQFactory.Create(this.MQConfig, MessageQueueTypeEnum.RabbitMq, null, applicationId);

            if (!string.IsNullOrEmpty(this.MQConfig.ProducerID))
            {
                this.MsgQueue.DeleteMQ(this.MQConfig.ProducerID, true, true);
            }

            string str = IdentityHelper.NewSequentialGuid().ToString("N");

            if (string.IsNullOrEmpty(this.MQConfig.Exchange))
            {
                this.MQConfig.Exchange = MQDefaultSetting._Exchange;
            }
            MQMsgResponse response1 = new MQMsgResponse
            {
                Exchange         = this.MQConfig.Exchange,
                ResponseQueue    = MQDefaultSetting._prefixQueue + "-" + str,
                ResponseRouteKey = str
            };

            this._mQMsgResponse = response1;
            if (mQMsgRequest == null)
            {
                MQMsgRequest request1 = new MQMsgRequest
                {
                    Exchange        = this.MQConfig.Exchange,
                    RequestRouteKey = MQDefaultSetting._RequestRouteKey
                };
                this._mQMsgRequest = request1;
            }
            else
            {
                this._mQMsgRequest = mQMsgRequest;
            }
        }