Example #1
0
 public void ClearMessagesInProgress() => _messageQueue.Clear();
Example #2
0
        public void Dispatch(MessageDispatch dispatch)
        {
            var listener = _listener;

            try
            {
                lock ( _syncRoot )
                {
                    if (_clearDispatchList)
                    {
                        // we are reconnecting so lets flush the in progress messages
                        _clearDispatchList = false;
                        _unconsumedMessages.Clear();

                        // on resumption a pending delivered ACK will be out of sync with
                        // re-deliveries.
                        _pendingAck = null;
                    }

                    if (!_unconsumedMessages.Stopped)
                    {
                        if (listener != null && _unconsumedMessages.Started)
                        {
                            var message = CreateStompMessage(dispatch);

                            BeforeMessageIsConsumed(dispatch);

                            try
                            {
                                var expired = !IgnoreExpiration && message.IsExpired();

                                if (!expired)
                                {
                                    listener(message);
                                }

                                AfterMessageIsConsumed(dispatch, expired);
                            }
                            catch (Exception e)
                            {
                                if (_session.IsAutoAcknowledge || _session.IsIndividualAcknowledge)
                                {
                                    // Redeliver the message
                                }
                                else
                                {
                                    // Transacted or Client ACK: Deliver the next message.
                                    AfterMessageIsConsumed(dispatch, false);
                                }

                                Tracer.Error(ConsumerInfo.ConsumerId + " Exception while processing message: " + e);
                            }
                        }
                        else
                        {
                            _unconsumedMessages.Enqueue(dispatch);
                        }
                    }
                }

                if (++_dispatchedCount % 1000 != 0)
                {
                    return;
                }
                _dispatchedCount = 0;
                Thread.Sleep(1);
            }
            catch (Exception e)
            {
                _session.Connection.OnSessionException(_session, e);
            }
        }