예제 #1
0
        public CommunicateChannel(IMessageConnection connection, PublisherContext publisherContext)
        {
            _connection = connection;

            _publisherContext = publisherContext;

            PublisherBind(publisherContext);
        }
        private ICommunicateChannel CreateChannel(PublisherContext publisherContext)
        {
            if(!_channelPools.Any() || _channelPools.Last().IsFull())
                _channelPools.Add(new CommunicateChannelFactory(_endpoint));

            var channel = _channelPools.Last().GetChannel(publisherContext);

            return channel;
        }
예제 #3
0
        public ICommunicateChannel GetChannel(PublisherContext publisherContext)
        {
            CheckConnection();

            if (!_channelPools.ContainsKey(publisherContext.ExchangeName))
            {
                var channel = new CommunicateChannel(_connection, publisherContext);

                _channelPools.TryAdd(publisherContext.ExchangeName, channel);
            }
            return _channelPools[publisherContext.ExchangeName];
        }
        public ICommunicateChannel GetChannel(PublisherContext publisherContext)
        {
            var communicateChannel = default(ICommunicateChannel);

            for (var i = 0; i < _channelPools.Count; i++)
            {
                if (_channelPools[i].ContainsChannel(publisherContext))
                {
                    communicateChannel = _channelPools[i].GetChannel(publisherContext);
                    break;
                }
            }

            if (communicateChannel != null) return communicateChannel;

            return CreateChannel(publisherContext);
        }
예제 #5
0
        private void PublisherBind(PublisherContext publisherContext)
        {
            _channel = _connection.CreateChannel();

            _channel.ExchangeDeclare(publisherContext.ExchangeName, publisherContext.ExchangeType, true);
        }
예제 #6
0
 public bool ContainsChannel(PublisherContext publisherContext)
 {
     return _channelPools.ContainsKey(publisherContext.ExchangeName);
 }