public static HubConfiguration UseRabbitMq(this HubConfiguration @this, RabbitMqScaleoutConfiguration scaleoutConfiguration)
        {
            var bus = new Lazy<RabbitMqMessageBus>(() => new RabbitMqMessageBus(@this.Resolver, scaleoutConfiguration));

            @this.Resolver.Register(typeof (IMessageBus), () => bus.Value);

            return @this;
        }
 private static ConnectionFactory CreateConnectionFactory(RabbitMqScaleoutConfiguration configuration)
 {
     var connectionFactory = new ConnectionFactory
     {
         UserName = configuration.UserName,
         Password = configuration.Password,
         VirtualHost = configuration.VirtualHost ?? "",
         Protocol = new Protocol()
     };
     return connectionFactory;
 }
        public RabbitMqMessageBus(IDependencyResolver resolver, RabbitMqScaleoutConfiguration configuration)
            : base(resolver, configuration)
        {
            Open(0);
            
            var connectionFactory = CreateConnectionFactory(configuration);

            connection = connectionFactory.CreateConnection();

            model = connection.CreateModel();

            var exchange = configuration.ExchangeName ?? "messages";

            model.QueueDeclare(configuration.QueueName, false, false, true, new Hashtable());
            model.ExchangeDeclare(exchange, ExchangeType.Fanout);
            model.QueueBind(configuration.QueueName, exchange, "");

            consumerTag = model.BasicConsume(configuration.QueueName, true, new Consumer(this.OnReceived));
        }
        public RabbitMqMessageBus(IDependencyResolver resolver, RabbitMqScaleoutConfiguration configuration)
            : base(resolver, configuration)
        {
            Open(0);

            var connectionFactory = CreateConnectionFactory(configuration);

            connection = connectionFactory.CreateConnection();

            model = connection.CreateModel();

            model.QueueDeclare(configuration.QueueName, false, false, true, new Hashtable());
            model.ExchangeDeclare(configuration.ExchangeName, ExchangeType.Fanout);
            model.QueueBind(configuration.QueueName, configuration.ExchangeName, "");

            consumerTag = model.BasicConsume(configuration.QueueName, true, new Consumer(this.OnReceived));

            this.configuration = configuration;
        }
Ejemplo n.º 5
0
 private static ConnectionFactory CreateConnectionFactory(RabbitMqScaleoutConfiguration configuration)
 {
     if (configuration.RabbitMqUri != null)
     {
         return new ConnectionFactory()
         {
             Uri = configuration.RabbitMqUri.ToString(),
         };
     }
     else
     {
         return new ConnectionFactory
         {
             HostName = configuration.HostName,
             UserName = configuration.UserName,
             Password = configuration.Password,
             VirtualHost = configuration.VirtualHost,
             Protocol = new Protocol(),
             Port = configuration.Port,
         };
     }
 }
 private static ConnectionFactory CreateConnectionFactory(RabbitMqScaleoutConfiguration configuration)
 {
     if (configuration.RabbitMqUri != null)
     {
         return(new ConnectionFactory()
         {
             Uri = configuration.RabbitMqUri.ToString(),
         });
     }
     else
     {
         return(new ConnectionFactory
         {
             HostName = configuration.HostName,
             UserName = configuration.UserName,
             Password = configuration.Password,
             VirtualHost = configuration.VirtualHost,
             Protocol = new Protocol(),
             Port = configuration.Port,
         });
     }
 }