public void Start() { var channel = _channelPools.GetChannel(_consumerContext); if (channel == null) throw new ApplicationException("can not start the message of consumer."); var listenerTask = new Task(() => { while (!_cancellation.IsCancellationRequested) { var receiveMessage = channel.Receive(); if (receiveMessage == null) { Thread.Sleep(1); continue; } var messageWrapper = _binarySerializer.Deserialize<MessageWrapper>(receiveMessage.ByteDatas); var messageContext = new MessageContext(messageWrapper, _consumerContext, receiveMessage.DeliveryTag); _messageHandler.Handle(messageContext); } }); listenerTask.Start(); }
public void Handle(MessageContext context) { var channelPools = DependencyResolver.Resolve<CommunicateChannelFactoryPool>(); var replyChannel = channelPools.GetChannel(new PublisherContext(context.MessageWrapper.ExchangeName, MessageExchangeType.Direct, false, true, true)); var binarySerializer = DependencyResolver.Resolve<IBinarySerializer>(); var responseMessage = new MessageWrapper() { AuotDelete = context.MessageWrapper.AuotDelete, Durable = context.MessageWrapper.Durable, ExchangeName = context.MessageWrapper.ExchangeName, IsRpcInvoke = context.MessageWrapper.IsRpcInvoke, Message = context.Response, MessageId = context.MessageWrapper.MessageId, MessageType = context.MessageWrapper.MessageType, ResponseRoutingKey = context.MessageWrapper.ResponseRoutingKey, RoutingKey = context.MessageWrapper.RoutingKey, TypeName = context.MessageWrapper.TypeName, TimeStamp = DateTime.Now }; replyChannel.Send(new SendMessage(binarySerializer.Serialize(responseMessage), context.MessageWrapper.ResponseRoutingKey)); }
public void Handle(MessageContext context) { try { Console.WriteLine("receive the response send.{0}, and now is {1}", context.MessageWrapper.TimeStamp, DateTime.Now); var message = context.MessageWrapper; context.SetResponse(message.Message as MessageHandleResult); var replyChannel = ReplyChannelPools.GetReplyChannel(message.MessageId); if (replyChannel == null) { Console.WriteLine("replyChannel is null."); return; } replyChannel.SetResult(context.Response); } catch (Exception ex) { Console.WriteLine("replyChannel is waiting is error."); } }
public void Handle(MessageContext context) { try { Stopwatch watch = new Stopwatch(); watch.Start(); if (context.Message is ICommand) { _commandProssor.Execute(context.Message as ICommand); } if (context.Message is IEvent) { var eventProssor = new DefaultEventProssor(); eventProssor.Execute(context.Message as IEvent); } context.SetResponse(new MessageHandleResult() { Message = "成功", Status = MessageStatus.Success, MessageId = context.Message.MessageId }); watch.Stop(); Console.WriteLine("message proccess time:{0}", watch.ElapsedMilliseconds); } catch (Exception ex) { context.SetResponse(new MessageHandleResult() { Message = ex.Message, Status = MessageStatus.Failure, MessageId = context.Message.MessageId }); } }
public void Handle(MessageContext context) { var channelPools = DependencyResolver.Resolve<CommunicateChannelFactoryPool>(); var channel = channelPools.GetChannel(context.ConsumerContext); channel.BasicAck(context.DeliveryTag); }
public void Handle(MessageContext context) { try { _handlers.ForEach(m => m.Handle(context)); } catch (BusinessException ex) { } catch (FrameworkException ex) { } catch (Exception ex) { } }
public void Handle(MessageContext context) { context.SetMessage(context.MessageWrapper.Message); }