public void ShouldCallExchangeDeclarePubSubTypeIsSubscribeAndExchangeBindingShouldDeclare()
        {
            const string queueName = "abc";
            _endpoint = new QueueEndpoint()
            {
                Name = "testendpoint",
                PubSubType = PubSubType.Subscribe,
                Subscription = new SubscriptionConfiguration()
                {
                    ExchangeBindings = new ExchangeBindingCollection()
                }
            };
            _endpoint.Subscription.ExchangeBindings.Add(
                new ExchangeBinding()
                {
                    Name = "e1",
                    RoutingKey = "rk",
                    Type = ExchangeType.Direct,
                    DeclareExchange = true
                });
            _channel.Stub(x => x.QueueDeclare()).Return(new QueueDeclareOk(queueName, 1, 1));
            var configurator = new ChannelConfigurator();
            configurator.ConfigureQueue(_endpoint, _channel);

            var binding = _endpoint.Subscription.ExchangeBindings[0];
            _channel.AssertWasCalled(x => x.ExchangeDeclare(
                binding.Name,
                "direct"));
        }
        public void ShouldCallQueueDeclareAndQueueBindWhenPubSubTypeIsSubscribe()
        {
            const string queueName = "abc";
            _endpoint = new QueueEndpoint()
            {
                Name = "testendpoint",
                PubSubType = PubSubType.Subscribe,
                Subscription = new SubscriptionConfiguration()
                {
                    ExchangeBindings = new ExchangeBindingCollection()
                }
            };
            _endpoint.Subscription.ExchangeBindings.Add(
                new ExchangeBinding()
                    {
                        Name = "e1",
                        RoutingKey = "rk"
                    });
            _channel.Stub(x => x.QueueDeclare()).Return(new QueueDeclareOk(queueName, 1, 1));
            var configurator = new ChannelConfigurator();
            configurator.ConfigureQueue(_endpoint, _channel);

            _channel.AssertWasCalled(x => x.QueueDeclare());
            _channel.AssertWasCalled(x => x.QueueBind(
                queueName,
                _endpoint.Subscription.ExchangeBindings[0].Name,
                _endpoint.Subscription.ExchangeBindings[0].RoutingKey));
        }
示例#3
0
        public virtual ConnectionFactory GetConnectionFactory(QueueEndpoint endpoint)
        {
            _logger.Log("Creating connection factory");
            _logger.Log("Hostname: '" + (endpoint.Host ?? "") + "'");
            var factory = new ConnectionFactory()
                       {
                           HostName = endpoint.Host
                       };
            _logger.Log("VirtualHostName: '" + (endpoint.VirtualHost ?? "") + "'");
            if (!string.IsNullOrEmpty(endpoint.VirtualHost))
            {
                _logger.Log("Setting virtual host");
                factory.VirtualHost = endpoint.VirtualHost;
            }
            _logger.Log("Port: " + (endpoint.Port.HasValue ? endpoint.Port.Value.ToString() : "[not set]"));
            if(endpoint.Port.HasValue)
            {
                factory.Port = endpoint.Port.Value;
            }

            if (!string.IsNullOrEmpty(endpoint.User))
            {
                _logger.Log("Setting user and password");
                factory.UserName = endpoint.User;
                factory.Password = endpoint.Password;
            }
            return factory;
        }
示例#4
0
 private void HandleExchange(QueueEndpoint endpoint, IModel channel)
 {
     if (
         endpoint.Exchange != null
         &&
         !string.IsNullOrEmpty(endpoint.Exchange.Name))
     {
         LogExchangeDeclareData(endpoint);
         channel.ExchangeDeclare(endpoint.Exchange.Name, endpoint.Exchange.Type.ToString().ToLower(),
                                 endpoint.Exchange.Durable);
     }
 }
示例#5
0
 protected void SetupEndpoint(string virtualHost, string queueName, string exchangeName)
 {
     if (!string.IsNullOrWhiteSpace(exchangeName))
     {
         Exchange = new ExchangeConfiguration() { Name = exchangeName, Type = RabbitMQUtil.ExchangeType.Fanout };
     }
     QueueEndpoint = new QueueEndpoint()
     {
         VirtualHost = virtualHost,
         RoutingKey = queueName,
         Exchange = Exchange
     };
 }
示例#6
0
        protected ConnectionFactory CreateFactoryMock(QueueEndpoint endPoint, IBasicProperties properties, byte[] data)
        {
            SetupModel(endPoint, properties, data);
            var connection = MockRepository.GenerateStub<IConnection>();
            connection
                .Stub(x => x.CreateModel())
                .Return(Model);

            var factory = MockRepository.GenerateStub<ConnectionFactory>();
            factory.Stub(x => x.CreateConnection())
                .Return(connection);
            return factory;
        }
示例#7
0
 private static void HandleSubscription(QueueEndpoint endpoint, IModel channel)
 {
     if (endpoint.Subscription == null)
     {
         throw new InvalidOperationException(
             "No subscription configuration was supplied. When an endpoints PubSubType is 'Subscribe', subscription configuration is mandatory.");
     }
     var queueName = string.IsNullOrWhiteSpace(endpoint.Subscription.QueueName)
                         ? channel.QueueDeclare()
                         : channel.QueueDeclare(endpoint.Subscription.QueueName, endpoint.Subscription.Durable, false,
                                                false, null);
     for (var x = 0; x < endpoint.Subscription.ExchangeBindings.Count; x++)
     {
         var exchangeBinding = endpoint.Subscription.ExchangeBindings[x];
         if (exchangeBinding.DeclareExchange)
         {
             channel.ExchangeDeclare(exchangeBinding.Name, exchangeBinding.Type.ToString().ToLower());
         }
         channel.QueueBind(queueName, exchangeBinding.Name, exchangeBinding.RoutingKey);
     }
 }
示例#8
0
 private void LogExchangeDeclareData(QueueEndpoint endpoint)
 {
     _logger.Log("Declaring exchange: " + endpoint.Exchange.Name);
     _logger.Log("Exchange type: " + endpoint.Exchange.Type.ToString());
     _logger.Log("Exchange durable: " + endpoint.Exchange.Durable.ToString());
 }
示例#9
0
 public virtual void ConfigureQueue(QueueEndpoint endpoint, IModel channel)
 {
     HandleExchange(endpoint, channel);
     if (endpoint.PubSubType != PubSubType.Subscribe) return;
     HandleSubscription(endpoint, channel);
 }
示例#10
0
 public virtual void ConfigureErrorHandling(QueueEndpoint endpoint, IModel channel)
 {
     HandleErrorConfig(endpoint.Subscription, channel);
 }
        public void ShouldCallQueueDeclareWithParametersWhenPubSubTypeIsSubscribeAndRoutingKeyIsSet()
        {
            const string queueName = "abc";
            var expectedResult = new QueueDeclareOk(queueName, 1, 1);
            _endpoint = new QueueEndpoint()
            {
                Name = "testendpoint",
                Exchange = new ExchangeConfiguration() { Name = "ex1" },
                PubSubType = PubSubType.Subscribe,
                RoutingKey = queueName,
                Subscription = new SubscriptionConfiguration() { QueueName = "abckduf", NoAck = false }
            };
            _endpoint.Subscription.ExchangeBindings.Add(new ExchangeBinding() { Name = "e1" });
            _channel
                .Stub(x => x.QueueDeclare())
                .Return(new QueueDeclareOk(queueName, 1, 1));
            _channel
                .Stub(x => x.QueueDeclare(_endpoint.Subscription.QueueName, _endpoint.Subscription.NoAck, false, false, null))
                .Return(expectedResult);
            var configurator = new ChannelConfigurator();
            configurator.ConfigureQueue(_endpoint, _channel);

            _channel.AssertWasCalled(x => x.QueueDeclare(_endpoint.Subscription.QueueName, _endpoint.Subscription.Durable, false, false, null));
            _channel.AssertWasCalled(x => x.QueueBind(expectedResult, _endpoint.Subscription.ExchangeBindings[0].Name, ""));
        }
示例#12
0
 protected void SetupEndpoint(string name, string virtualHost, string routingKey)
 {
     QueueEndpoint = new QueueEndpoint() { Name = name, RoutingKey = routingKey, VirtualHost = virtualHost, PubSubType = PubSubType.Subscribe };
 }
 public void ShouldThrowExceptionIfPubSubTypeIsSubscribeAndNoSubscriptionConfigExists()
 {
     const string queueName = "abc";
     var expectedResult = new QueueDeclareOk(queueName, 1, 1);
     _endpoint = new QueueEndpoint()
     {
         Name = "testendpoint",
         Exchange = new ExchangeConfiguration() { Name = "ex1" },
         PubSubType = PubSubType.Subscribe,
         RoutingKey = queueName,
         Subscription = null
     };
     var configurator = new ChannelConfigurator();
     configurator.ConfigureQueue(_endpoint, _channel);
 }
        public void ShouldNotCallQueueDeclareAndQueueBindWhenPubSubTypeIsPublish()
        {
            const string queueName = "abc";
            _endpoint = new QueueEndpoint()
            {
                Name = "testendpoint",
                Exchange = new ExchangeConfiguration() { Name = "ex1" },
                Subscription = new SubscriptionConfiguration() { QueueName = "asdf" },
                PubSubType = PubSubType.Publish
            };
            _channel.Stub(x => x.QueueDeclare()).Return(new QueueDeclareOk(queueName, 1, 1));
            var configurator = new ChannelConfigurator();
            configurator.ConfigureQueue(_endpoint, _channel);

            _channel.AssertWasNotCalled(x => x.QueueDeclare());
            _channel.AssertWasNotCalled(x => x.QueueBind(_endpoint.Subscription.QueueName, _endpoint.Exchange.Name, ""));
        }
 public void ShouldNotCallExchangeDeclareIfExchangesNameIsEmpty()
 {
     _endpoint = new QueueEndpoint()
     {
         Name = "testendpoint",
         Exchange = new ExchangeConfiguration() { Name = string.Empty, Type = ExchangeType.Fanout},
         PubSubType = PubSubType.Publish,
         RoutingKey = "asdf",
         Subscription = null
     };
     var configurator = new ChannelConfigurator();
     configurator.ConfigureQueue(_endpoint, _channel);
     _channel.AssertWasNotCalled(x => x.ExchangeDeclare(_endpoint.Exchange.Name, _endpoint.Exchange.Type.ToString().ToLower()));
 }
示例#16
0
 protected void SetupModel(QueueEndpoint endPoint, IBasicProperties properties, byte[] data)
 {
     Model = MockRepository.GenerateStub<IModel>();
     Model.Stub(x => x.QueueDeclare(endPoint.RoutingKey, false, false, false, null))
         .Return(new QueueDeclareOk(endPoint.RoutingKey, 1, 1));
     Model.Stub(x => x.CreateBasicProperties())
         .Return(properties);
     Model.Stub(x => x.BasicPublish(Exchange != null ? Exchange.Name : null, endPoint.RoutingKey, properties, data));
 }
示例#17
0
 protected void SetupModel(QueueEndpoint endPoint, IBasicProperties properties, byte[] data)
 {
     Model = MockRepository.GenerateStub<IModel>();
     Model.Stub(x => x.QueueDeclare(endPoint.RoutingKey, false, false, false, null))
         .Return(new QueueDeclareOk(endPoint.RoutingKey, 1, 1));
     Model.Stub(x => x.BasicConsume(endPoint.RoutingKey, true, Consumer))
         .Return(null);
 }
示例#18
0
 protected void SetupModelBasicGet(QueueEndpoint endPoint, BasicGetResult result)
 {
     Model.Stub(x => x.BasicGet(endPoint.RoutingKey, false)).Return(result);
 }
示例#19
0
 private void LogEndpointData(ConnectionFactory factory, QueueEndpoint endpoint)
 {
     _logger.Log("Host: " + factory.HostName);
     _logger.Log("Virtual host: " + factory.VirtualHost);
     _logger.Log("ExchangeName: '" + GetExchangeName(endpoint) + "'");
     _logger.Log("RoutingKey: '" + endpoint.RoutingKey + "'");
 }
示例#20
0
 protected void ValidateEndpoint(QueueEndpoint endpoint)
 {
     if (endpoint.PubSubType == PubSubType.Publish) throw new InvalidOperationException("ReceiveListener cannot be started on an endpoint with PubSubType.Publish.");
 }
示例#21
0
 private static string GetExchangeName(QueueEndpoint endpoint)
 {
     return endpoint.Exchange != null ? endpoint.Exchange.Name : string.Empty;
 }