private void CallBack(object obj, BasicDeliverEventArgs ea, Action <MQMessage> callAction) { if (callAction != null) { try { MQMessage message = ea.Body.ToMessage(); message.MsgId = ea.BasicProperties.MessageId; message.Label = ea.BasicProperties.CorrelationId; message.MsgId = ea.BasicProperties.MessageId; if (message.Response != null) { MQMsgRequest request1 = new MQMsgRequest { Exchange = message.Response.Exchange, RequestRouteKey = message.Response.ResponseRouteKey }; message.Request = request1; } callAction(message); } catch (Exception exception) { Console.WriteLine(exception.Message); } finally { this.Channel.BasicAck(ea.DeliveryTag, false); } } }
public RpcServer(DistributedMQConfig distributedMQConfig, IList <string> routeKeyList, string applicationId) : base(distributedMQConfig) { this.MQConfig = distributedMQConfig; this.MsgQueue = MQFactory.Create(distributedMQConfig, MessageQueueTypeEnum.RabbitMq, routeKeyList, applicationId); this.MsgQueue.ReceiveMQ(delegate(MQMessage msg) { if ((msg != null) && (msg.Response != null)) { MQMsgRequest request1 = new MQMsgRequest { Exchange = msg.Response.Exchange, RequestRouteKey = msg.Response.ResponseRouteKey }; msg.Request = request1; msg.Response = null; } if (this.ReciveMsgedEvent != null) { this.ReciveMsgedEvent(msg); } }); }
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; } }
private void CallBack(object obj, BasicDeliverEventArgs ea, Action <MQMessage> callAction) { if (callAction != null) { try { MQMessage message = ea.Body.ToMessage(); message.MsgId = ea.BasicProperties.MessageId; if (string.IsNullOrEmpty(this._ApplicationCode) || (!string.IsNullOrEmpty(this._ApplicationCode) && (this._ApplicationCode == ea.BasicProperties.CorrelationId))) { message.Label = ea.BasicProperties.CorrelationId; message.MsgId = ea.BasicProperties.MessageId; if (message.Response != null) { MQMsgRequest request1 = new MQMsgRequest { Exchange = message.Response.Exchange, RequestRouteKey = message.Response.ResponseRouteKey }; message.Request = request1; } callAction(message); } else { IOHelper.WriteLine("没有匹配到路由!", (ConsoleColor)ConsoleColor.Red); } } catch (Exception exception) { Console.WriteLine(exception.Message); } finally { this.Channel.BasicAck(ea.DeliveryTag, false); } } }