SetChannel() публичный Метод

Set the IModel (aka channel)
public SetChannel ( IModel channel ) : void
channel IModel
Результат void
Пример #1
0
        private Subscription CreateSubscription <T>(string subscriptionName, Func <IModel, string, IBasicConsumer> createConsumer)
        {
            var subscription = new Subscription {
                SubscriptionName = subscriptionName
            };
            var    id = Guid.NewGuid();
            Action subscriptionAction = () =>
            {
                subscription.QueueName   = _routeFinder.FindQueueName <T>(subscriptionName);
                subscription.ConsumerTag = string.Format("{0}-{1}", subscriptionName, Guid.NewGuid());
                var channel = _connection.CreateChannel();
                channel.ModelShutdown += (c, reason) =>
                {
                    RaiseConsumerDisconnectedEvent(subscription);
                    TryReconnect(c, id, reason);
                };

                if (Global.PreFetchSize <= ushort.MaxValue)
                {
                    channel.BasicQos(0, (ushort)Global.PreFetchSize, false);
                }
                else
                {
                    _watcher.WarnFormat("The prefetch size is too high {0}, maximum {1}, the queue will prefetch all the msgs", Global.PreFetchSize, ushort.MaxValue);
                }

                _createdChannels.Add(channel);

                subscription.SetChannel(channel);

                var consumer = createConsumer(channel, subscription.ConsumerTag);
                if (consumer is DefaultBasicConsumer)
                {
                    (consumer as DefaultBasicConsumer).ConsumerTag = subscription.ConsumerTag;
                }
                //NOTE: The message will still be on the Unacknowledged list until it's processed and the method
                //      DoAck is call.
                channel.BasicConsume(subscription.QueueName, false /* noAck, must be false */, subscription.ConsumerTag, consumer);
                _watcher.InfoFormat("Subscribed to: {0} with subscriptionName: {1}", subscription.QueueName, subscription.SubscriptionName);
            };

            _subscribeActions[id] = subscriptionAction;
            TrySubscribe(subscriptionAction);
            return(subscription);
        }
Пример #2
0
        private Subscription CreateSubscription(string subscriptionName, string queueName, Func <IModel, IBasicConsumer> createConsumer, ushort prefetchSize)
        {
            var subscription = new Subscription {
                SubscriptionName = subscriptionName
            };
            var id = Guid.NewGuid();

            Action subscriptionAction = () =>
            {
                subscription.QueueName   = queueName;
                subscription.ConsumerTag = $"{subscriptionName}-{Guid.NewGuid()}";
                var channel = _connection.CreateChannel();
                channel.ModelShutdown += (c, reason) =>
                {
                    if (_disposed)
                    {
                        return;
                    }
                    RaiseConsumerDisconnectedEvent(subscription);
                    TryReconnect((IModel)c, id, reason);
                };

                channel.BasicQos(0, prefetchSize, false);

                _createdChannels.Add(channel);

                var consumer = createConsumer(channel);
                if (consumer is DefaultBasicConsumer)
                {
                    (consumer as DefaultBasicConsumer).ConsumerTag = subscription.ConsumerTag;
                }

                Subscription.OutstandingDeliveryTags[subscription.ConsumerTag] = new List <ulong>();
                subscription.SetChannel(channel);
                //NOTE: The message will still be on the Unacknowledged list until it's processed and the method
                //      DoAck is call.
                channel.BasicConsume(subscription.QueueName, false /* noAck, must be false */, subscription.ConsumerTag, consumer);
                _watcher.InfoFormat("Subscribed to: {0} with subscriptionName: {1}", subscription.QueueName, subscription.SubscriptionName);
            };

            _subscribeActions[id] = subscriptionAction;
            TrySubscribe(subscriptionAction);
            return(subscription);
        }