Exemple #1
0
 protected virtual Task SendAsync(IMessageContext commandContext, CancellationToken cancellationToken)
 {
     var commandState = BuildMessageState(commandContext, cancellationToken);
     commandState.CancellationToken.Register(OnCancel, commandState);
     CommandStateQueue.Add(commandState.MessageID, commandState);
     _toBeSentCommandQueue.Add(commandContext, cancellationToken);
     return commandState.TaskCompletionSource.Task;
 }
Exemple #2
0
 protected void OnCancel(object state)
 {
     var messageState = state as MessageState;
     if (messageState != null)
     {
         CommandStateQueue.TryRemove(messageState.MessageID);
     }
 }
Exemple #3
0
        protected override Task SendAsync(IMessageContext commandContext, CancellationToken cancellationToken)
        {
            MessageState commandState = BuildMessageState(commandContext, cancellationToken);

            commandState.CancellationToken.Register(OnCancel, commandState);
            CommandStateQueue.Add(commandState.MessageID, commandState);
            Task.Factory.StartNew(() => {
                _commandConsumer.EnqueueMessage(commandContext.GetFrame());
                _Logger.InfoFormat("send to distributor/consumer commandID:{0} payload:{1}",
                                   commandContext.MessageID, commandContext.ToJson());
            });
            return(commandState.TaskCompletionSource.Task);
        }
Exemple #4
0
 protected override void ConsumeMessage(IMessageReply reply)
 {
     _Logger.InfoFormat("Handle reply:{0} content:{1}", reply.MessageID, reply.ToJson()); 
     var messageState = CommandStateQueue[reply.MessageID] as IFramework.Message.MessageState;
     if (messageState != null)
     {
         CommandStateQueue.TryRemove(reply.MessageID);
         if (reply.Result is Exception)
         {
             messageState.TaskCompletionSource.TrySetException(reply.Result as Exception);
         }
         else
         {
             messageState.TaskCompletionSource.TrySetResult(reply.Result);
         }
     }
 }
Exemple #5
0
        protected override void ConsumeMessage(MessageReply reply, EQueueProtocols.QueueMessage queueMessage)
        {
            _Logger.DebugFormat("Handle reply:{0} content:{1}", reply.MessageID, reply.ToJson());
            var messageState = CommandStateQueue[reply.MessageID] as MessageState;

            if (messageState != null)
            {
                CommandStateQueue.TryRemove(reply.MessageID);
                if (reply.Result is Exception)
                {
                    messageState.TaskCompletionSource.TrySetException(reply.Result as Exception);
                }
                else
                {
                    messageState.TaskCompletionSource.TrySetResult(reply.Result);
                }
            }
        }