예제 #1
0
        public MessageEnvelope CallRaw(byte[] data,
                                       string routingKey,
                                       IBasicProperties messageProperties,
                                       RpcSendOptions options)
        {
            // CreateBasicProperties doesnt need the lock
            var prop = messageProperties ?? _model.CreateBasicProperties();

            using (var @event = new AutoResetEvent(false))
            {
                prop.CorrelationId         = Guid.NewGuid().ToString();
                prop.Expiration            = options.Timeout.TotalMilliseconds.ToString();
                _waits[prop.CorrelationId] = @event;

                lock (_model)
                {
                    var returnQueue = GetOrCreateReturnQueue(routingKey);
                    prop.ReplyTo = returnQueue;
                }

                lock (_model)
                {
                    _model.BasicPublish(_exchange, routingKey, prop, data);
                }

                if ([email protected](options.Timeout))
                {
                    MessageEnvelope val;
                    _replyData.TryRemove(prop.CorrelationId, out val);

                    LogAdapter.LogDebug("RpcHelper", "Timeout'ed correlation id " + prop.CorrelationId + " for " + routingKey);

                    throw new TimeoutException("Timeout waiting for reply.");
                }

                MessageEnvelope reply;
                _replyData.TryRemove(prop.CorrelationId, out reply);
                return(reply);
            }
        }
        private void OnProc()
        {
            try
            {
                while (!_closed)
                {
                    var args = base.Queue.Dequeue();
                    if (args == null)
                    {
                        continue;
                    }

                    if (_consumers.Count == 0)
                    {
                        // throwing out messages due to lack of consumers

                        if (LogAdapter.LogEnabled)
                        {
                            LogAdapter.LogDebug(this.GetType().FullName,
                                                "SharedQueueConsumer dropping message due to lack of consumers subscribed");
                        }

                        continue;
                    }

                    PublishToConsumers(args);
                }
            }
            catch (Exception e)
            {
                if (LogAdapter.LogEnabled)
                {
                    LogAdapter.LogError(this.GetType().FullName, "SharedQueueConsumer error ", e);
                }
            }
        }
예제 #3
0
 private void OnConnectionUnblocked(object sender, EventArgs e)
 {
     LogAdapter.LogWarn("Connection", "Connection Unblocked - broker running is back on its feet");
 }
예제 #4
0
 private void OnConnectionBlocked(object sender, ConnectionBlockedEventArgs e)
 {
     LogAdapter.LogWarn("Connection", "Connection blocked - broker running low on resources (memory or disk)");
 }
예제 #5
0
        private void ResetQueueCache()
        {
            LogAdapter.LogWarn("RpcHelper", "Reseting return queue cache.");

            _routing2RetQueue.Clear();
        }
예제 #6
0
        public void HandleModelShutdown(object model, ShutdownEventArgs reason)
        {
            LogAdapter.LogWarn("RpcHelper", "Model Shutdown. Reason: " + reason);

            ResetQueueCache();
        }
예제 #7
0
        public override void HandleBasicCancel(string consumerTag)
        {
            base.HandleBasicCancel(consumerTag);

            LogAdapter.LogWarn("StreamerConsumer", "consumer has been cancelled unexpectedly: tag " + consumerTag);
        }