Esempio 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;
        }
 /// <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);
 }
 /// <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();
 }
Esempio n. 4
0
 public void AckMessage(MessageTransportContext message)
 {
     foreach (var queue in _readers)
     {
         if (queue.Name == message.QueueName)
         {
             queue.AckMessage(message);
         }
     }
 }
Esempio n. 5
0
 public void AckMessage(MessageTransportContext message)
 {
     foreach (var queue in _readers)
     {
         if (queue.Name == message.QueueName)
         {
             queue.AckMessage(message);
         }
     }
 }
Esempio 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);
         }
     }
 }
Esempio 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);
         }
     }
 }
        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);
            }
        }
Esempio 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;
            }
        }
Esempio 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));
            }
        }
Esempio 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);
        }
Esempio n. 14
0
 public void AckMessage(MessageTransportContext message)
 {
 }
Esempio n. 15
0
 public void TryNotifyNack(MessageTransportContext context)
 {
 }
Esempio 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);
 }
Esempio n. 18
0
 public DispatchRecoveryFailed(Exception exception, MessageTransportContext message, string queueName)
 {
     DispatchException = exception;
     Message = message;
     QueueName = queueName;
 }
Esempio 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);
        }
Esempio n. 21
0
 public MessageAckFailed(Exception exception, MessageTransportContext context)
 {
     Exception = exception;
     Context = context;
 }
 public static GetEnvelopeResult Success(MessageTransportContext message)
 {
     return new GetEnvelopeResult(message, GetEnvelopeResultState.Success);
 }
Esempio n. 23
0
 public void AckMessage(MessageTransportContext message)
 {
     
 }
Esempio n. 24
0
 public static GetEnvelopeResult Success(MessageTransportContext message)
 {
     return(new GetEnvelopeResult(message, GetEnvelopeResultState.Success));
 }
Esempio n. 25
0
 GetEnvelopeResult(MessageTransportContext message, GetEnvelopeResultState state)
 {
     _message = message;
     State    = state;
 }
 public bool TakeMessage(CancellationToken token, out MessageTransportContext context)
 {
     context = new MessageTransportContext(null, new byte[0], "Name");
     return false;
 }
Esempio n. 27
0
        public void TryNotifyNack(MessageTransportContext context)
        {
            var id = (int)context.TransportMessage;

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

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