Пример #1
0
 internal static void AddMessageProperties(DirectoryQueue queue, DirectoryQueueMessage cloudMessage, IStorageQueuePropertiesProvider props)
 {
     if (null == props || (null == props.TimeToLive && null == props.InitialVisibilityDelay))
     {
         queue.AddMessage(cloudMessage);
     }
     else
     {
         queue.AddMessage(cloudMessage, props.TimeToLive, props.InitialVisibilityDelay);
     }
 }
Пример #2
0
        public IActorMessage GetMessage()
        {
            if (!recieveMessagesOnly)
            {
                throw new OperatorCannotRecieveMessagesException();
            }

            if (null != hangUp)
            {
                return(hangUp);
            }

            try
            {
                // Get the next message off of the azure queue
                DirectoryQueueMessage next = this.queue.GetMessage(this.retrieveVisibilityTimeout);

                if (null == next)
                {
                    return(null);
                }

                if (next.DequeueCount > maxDequeueCount)
                {
                    if (null != this.deadLetterQueue)
                    {
                        deadLetterQueue.AddMessage(next);
                    }
                    queue.DeleteMessage(next);
                    return(null);
                }

                IActorMessage msg = null;
                if (typeof(MsgType) == typeof(string))
                {
                    msg = next.AsString.ToActorMessage();
                }
                else if (typeof(MsgType) == typeof(byte[]))
                {
                    msg = next.AsBytes.ToActorMessage();
                }
                else
                {
                    byte[] msgBytes = next.AsBytes;
                    var    t        = Telegraph.Instance.Ask(new DeserializeMessage <IActorMessage>(msgBytes));
                    msg = t.Result as IActorMessage;
                }

                if (null == msg.Status)
                {
                    msg.Status = new TaskCompletionSource <IActorMessage>();
                }

                msg.Status.Task.ContinueWith(p => queue.DeleteMessage(next));
                return(msg);
            }
            catch (Exception ex)
            {
                Exception foundEx = null;
                var       handler = this.FindExceptionHandler(_exceptionTypeToHandler, ex, out foundEx);

                if (null != handler)
                {
                    handler.Invoke(foundEx);
                }
                return(null);
            }
        }