Exemplo n.º 1
0
        public bool TakeMessage(CancellationToken token, out MessageTransportContext context)
        {
            while (!token.IsCancellationRequested)
            {
                for (var i = 0; i < _readers.Length; i++)
                {
                    var queue = _readers[i];

                    var message = queue.TryGetMessage();
                    switch (message.State)
                    {
                        case GetEnvelopeResultState.Success:

                            _emptyCycles = 0;
                            context = message.Message;
                            return true;
                        case GetEnvelopeResultState.Empty:
                            _emptyCycles += 1;
                            break;
                        case GetEnvelopeResultState.Exception:
                            // access problem, fall back a bit
                            break;
                        case GetEnvelopeResultState.Retry:
                            // this could be the poison
                            break;
                        default:
                            throw new ArgumentOutOfRangeException();
                    }
                    var waiting = _waiter(_emptyCycles);
                    token.WaitHandle.WaitOne(waiting);
                }
            }
            context = null;
            return false;
        }
Exemplo n.º 2
0
 /// <summary>
 /// ACKs the message by deleting it from the queue.
 /// </summary>
 /// <param name="message">The message context to ACK.</param>
 public void AckMessage(MessageTransportContext message)
 {
     if (message == null)
     {
         throw new ArgumentNullException("message");
     }
     _queue.DeleteMessage((CloudQueueMessage)message.TransportMessage);
 }
Exemplo n.º 3
0
 /// <summary>
 /// ACKs the message by deleting it from the queue.
 /// </summary>
 /// <param name="message">The message context to ACK.</param>
 public void AckMessage(MessageTransportContext message)
 {
     if (message == null)
     {
         throw new ArgumentNullException("message");
     }
     ((FileInfo)message.TransportMessage).Delete();
 }
Exemplo n.º 4
0
 public void AckMessage(MessageTransportContext message)
 {
     foreach (var queue in _readers)
     {
         if (queue.Name == message.QueueName)
         {
             queue.AckMessage(message);
         }
     }
 }
Exemplo n.º 5
0
 public void AckMessage(MessageTransportContext message)
 {
     foreach (var queue in _readers)
     {
         if (queue.Name == message.QueueName)
         {
             queue.AckMessage(message);
         }
     }
 }
Exemplo n.º 6
0
 public void AckMessage(MessageTransportContext message)
 {
     if (message == null) throw new ArgumentNullException("message");
     foreach (var queue in _readers)
     {
         if (queue.Name == message.QueueName)
         {
             queue.AckMessage(message);
         }
     }
 }
Exemplo n.º 7
0
 public void AckMessage(MessageTransportContext message)
 {
     if (message == null)
     {
         throw new ArgumentNullException("message");
     }
     foreach (var queue in _readers)
     {
         if (queue.Name == message.QueueName)
         {
             queue.AckMessage(message);
         }
     }
 }
Exemplo n.º 8
0
        public bool TakeMessage(CancellationToken token, out MessageTransportContext context)
        {
            while (!token.IsCancellationRequested)
            {
                // if incoming message is delayed and in future -> push it to the timer queue.
                // timer will be responsible for publishing back.

                byte[] envelope;
                var result = BlockingCollection<byte[]>.TakeFromAny(_queues, out envelope);
                if (result >= 0)
                {
                    context = new MessageTransportContext(result, envelope, _names[result]);
                    return true;
                }
            }
            context = null;
            return false;
        }
Exemplo n.º 9
0
        public GetEnvelopeResult TryGetMessage()
        {
            FileInfo message;

            try
            {
                message = _queue.EnumerateFiles().FirstOrDefault();
            }
            catch (Exception ex)
            {
                SystemObserver.Notify(new FailedToReadMessage(ex, _queueName));
                return(GetEnvelopeResult.Error());
            }

            if (null == message)
            {
                return(GetEnvelopeResult.Empty);
            }

            try
            {
                var buffer = File.ReadAllBytes(message.FullName);

                var unpacked = new MessageTransportContext(message, buffer, _queueName);
                return(GetEnvelopeResult.Success(unpacked));
            }
            catch (IOException ex)
            {
                // this is probably sharing violation, no need to
                // scare people.
                if (!IsSharingViolation(ex))
                {
                    SystemObserver.Notify(new FailedToAccessStorage(ex, _queue.Name, message.Name));
                }
                return(GetEnvelopeResult.Retry);
            }
            catch (Exception ex)
            {
                SystemObserver.Notify(new MessageInboxFailed(ex, _queue.Name, message.FullName));
                // new poison details
                return(GetEnvelopeResult.Retry);
            }
        }
Exemplo n.º 10
0
        public bool TakeMessage(CancellationToken token, out MessageTransportContext context)
        {
            while (!token.IsCancellationRequested)
            {
                // if incoming message is delayed and in future -> push it to the timer queue.
                // timer will be responsible for publishing back.

                byte[] envelope;
                var    result = BlockingCollection <byte[]> .TakeFromAny(_queues, out envelope);

                if (result >= 0)
                {
                    context = new MessageTransportContext(result, envelope, _names[result]);
                    return(true);
                }
            }
            context = null;
            return(false);
        }
        public GetEnvelopeResult TryGetMessage()
        {
            FileInfo message;
            try
            {
                message = _queue.EnumerateFiles().FirstOrDefault();
            }
            catch (Exception ex)
            {
                SystemObserver.Notify(new FailedToReadMessage(ex, _queueName));
                return GetEnvelopeResult.Error();
            }

            if (null == message)
            {
                return GetEnvelopeResult.Empty;
            }

            try
            {
                var buffer = File.ReadAllBytes(message.FullName);

                var unpacked = new MessageTransportContext(message, buffer, _queueName);
                return GetEnvelopeResult.Success(unpacked);
            }
            catch (IOException ex)
            {
                // this is probably sharing violation, no need to 
                // scare people.
                if (!IsSharingViolation(ex))
                {
                    SystemObserver.Notify(new FailedToAccessStorage(ex, _queue.Name, message.Name));
                }
                return GetEnvelopeResult.Retry;
            }
            catch (Exception ex)
            {
                SystemObserver.Notify(new MessageInboxFailed(ex, _queue.Name, message.FullName));
                // new poison details
                return GetEnvelopeResult.Retry;
            }
        }
Exemplo n.º 12
0
        void ProcessMessage(MessageTransportContext context)
        {
            var dispatched = false;
            try
            {
                _dispatcher(context.Unpacked);

                dispatched = true;
            }
            catch (ThreadAbortException)
            {
                // we are shutting down. Stop immediately
                return;
            }
            catch (Exception dispatchEx)
            {
                // if the code below fails, it will just cause everything to be reprocessed later,
                // which is OK (duplication manager will handle this)

                SystemObserver.Notify(new MessageDispatchFailed(context, context.QueueName, dispatchEx));
                // quarantine is atomic with the processing
                _inbox.TryNotifyNack(context);
            }
            if (!dispatched)
                return;
            try
            {
                _inbox.AckMessage(context);
                // 3rd - notify.
                SystemObserver.Notify(new MessageAcked(context));

            }
            catch (ThreadAbortException)
            {
                // nothing. We are going to sleep
            }
            catch (Exception ex)
            {
                // not a big deal. Message will be processed again.
                SystemObserver.Notify(new MessageAckFailed(ex, context));
            }
        }
Exemplo n.º 13
0
        public bool TakeMessage(CancellationToken token, out MessageTransportContext context)
        {
            while (!token.IsCancellationRequested)
            {
                for (var i = 0; i < _readers.Length; i++)
                {
                    var queue = _readers[i];

                    var message = queue.TryGetMessage();
                    switch (message.State)
                    {
                    case GetEnvelopeResultState.Success:

                        _emptyCycles = 0;
                        context      = message.Message;
                        return(true);

                    case GetEnvelopeResultState.Empty:
                        _emptyCycles += 1;
                        break;

                    case GetEnvelopeResultState.Exception:
                        // access problem, fall back a bit
                        break;

                    case GetEnvelopeResultState.Retry:
                        // this could be the poison
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                    var waiting = _waiter(_emptyCycles);
                    token.WaitHandle.WaitOne(waiting);
                }
            }
            context = null;
            return(false);
        }
Exemplo n.º 14
0
 public void AckMessage(MessageTransportContext message)
 {
 }
Exemplo n.º 15
0
 public void TryNotifyNack(MessageTransportContext context)
 {
 }
Exemplo n.º 16
0
 public void TryNotifyNack(MessageTransportContext context)
 {
 }
 /// <summary>
 /// ACKs the message by deleting it from the queue.
 /// </summary>
 /// <param name="message">The message context to ACK.</param>
 public void AckMessage(MessageTransportContext message)
 {
     if (message == null) throw new ArgumentNullException("message");
     _queue.DeleteMessage((CloudQueueMessage) message.TransportMessage);
 }
Exemplo n.º 18
0
 public DispatchRecoveryFailed(Exception exception, MessageTransportContext message, string queueName)
 {
     DispatchException = exception;
     Message = message;
     QueueName = queueName;
 }
Exemplo n.º 19
0
 /// <summary>
 /// ACKs the message by deleting it from the queue.
 /// </summary>
 /// <param name="message">The message context to ACK.</param>
 public void AckMessage(MessageTransportContext message)
 {
     if (message == null) throw new ArgumentNullException("message");
     ((FileInfo) message.TransportMessage).Delete();
 }
        public void when_reader_ack_messages()
        {
            _queueWriter.PutMessage(Encoding.UTF8.GetBytes("message"));
            var msg = _statelessReader.TryGetMessage();

            var transportContext = new MessageTransportContext(
                msg.Message.TransportMessage
                , msg.Message.Unpacked
                , msg.Message.QueueName);

            _queueReader.AckMessage(transportContext);
            var msg2 = _statelessReader.TryGetMessage();

            Assert.AreEqual(GetEnvelopeResultState.Empty, msg2.State);
        }
Exemplo n.º 21
0
 public MessageAckFailed(Exception exception, MessageTransportContext context)
 {
     Exception = exception;
     Context = context;
 }
Exemplo n.º 22
0
 public static GetEnvelopeResult Success(MessageTransportContext message)
 {
     return new GetEnvelopeResult(message, GetEnvelopeResultState.Success);
 }
Exemplo n.º 23
0
 public void AckMessage(MessageTransportContext message)
 {
     
 }
Exemplo n.º 24
0
 public static GetEnvelopeResult Success(MessageTransportContext message)
 {
     return(new GetEnvelopeResult(message, GetEnvelopeResultState.Success));
 }
Exemplo n.º 25
0
 GetEnvelopeResult(MessageTransportContext message, GetEnvelopeResultState state)
 {
     _message = message;
     State    = state;
 }
Exemplo n.º 26
0
 public bool TakeMessage(CancellationToken token, out MessageTransportContext context)
 {
     context = new MessageTransportContext(null, new byte[0], "Name");
     return false;
 }
Exemplo n.º 27
0
        public void TryNotifyNack(MessageTransportContext context)
        {
            var id = (int)context.TransportMessage;

            _queues[id].Add(context.Unpacked);
        }
Exemplo n.º 28
0
 GetEnvelopeResult(MessageTransportContext message, GetEnvelopeResultState state)
 {
     _message = message;
     State = state;
 }
Exemplo n.º 29
0
 public MessageDispatchFailed(MessageTransportContext message, string queueName, Exception exception)
 {
     Exception = exception;
     Message = message;
     QueueName = queueName;
 }
Exemplo n.º 30
0
 public MessageAcked(MessageTransportContext attributes)
 {
     Context = attributes;
 }
Exemplo n.º 31
0
        public void TryNotifyNack(MessageTransportContext context)
        {
            var id = (int) context.TransportMessage;

            _queues[id].Add(context.Unpacked);
        }