Example #1
0
        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)
        {
            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.");
            }
        }