Inheritance: IConventions
コード例 #1
0
        public static IServiceProvider CreateServiceProvider(Action<IServiceRegister> registerServices)
        {
            Preconditions.CheckNotNull(registerServices, "registerServices");

            var serviceProvider = new DefaultServiceProvider();
            registerServices(serviceProvider);

            // we only want single instances of these shared services, so instantiate them here
            var logger = new ConsoleLogger();
            var serializer = new JsonSerializer();
            var conventions = new Conventions();

            // default service registration
            serviceProvider
                .Register<IEasyNetQLogger>(x => logger)
                .Register<ISerializer>(x => serializer)
                .Register<IConventions>(x => conventions)
                .Register<SerializeType>(x => TypeNameSerializer.Serialize)
                .Register<Func<string>>(x => CorrelationIdGenerator.GetCorrelationId)
                .Register<IClusterHostSelectionStrategy<ConnectionFactoryInfo>>(x => new DefaultClusterHostSelectionStrategy<ConnectionFactoryInfo>())
                .Register<IConsumerDispatcherFactory>(x => new ConsumerDispatcherFactory(x.Resolve<IEasyNetQLogger>()))
                .Register<IConsumerErrorStrategy>(x => new DefaultConsumerErrorStrategy(
                    x.Resolve<IConnectionFactory>(),
                    x.Resolve<ISerializer>(),
                    x.Resolve<IEasyNetQLogger>(),
                    x.Resolve<IConventions>()))
                .Register<IHandlerRunner>(x => new HandlerRunner(
                    x.Resolve<IEasyNetQLogger>(),
                    x.Resolve<IConsumerErrorStrategy>()))
                .Register<IInternalConsumerFactory>(x => new InternalConsumerFactory(
                    x.Resolve<IHandlerRunner>(),
                    x.Resolve<IEasyNetQLogger>(),
                    x.Resolve<IConventions>(),
                    x.Resolve<IConnectionConfiguration>(),
                    x.Resolve<IConsumerDispatcherFactory>()))
                .Register<IConsumerFactory>(x => new ConsumerFactory(x.Resolve<IInternalConsumerFactory>()))
                .Register<IConnectionFactory>(x => new ConnectionFactoryWrapper(
                    x.Resolve<IConnectionConfiguration>(),
                    x.Resolve<IClusterHostSelectionStrategy<ConnectionFactoryInfo>>()))
                .Register<IMessageValidationStrategy>(x => new DefaultMessageValidationStrategy(
                    x.Resolve<IEasyNetQLogger>(),
                    x.Resolve<SerializeType>()))
                .Register<IAdvancedBus>(x => new RabbitAdvancedBus(
                    x.Resolve<IConnectionFactory>(),
                    x.Resolve<SerializeType>(),
                    x.Resolve<ISerializer>(),
                    x.Resolve<IConsumerFactory>(),
                    x.Resolve<IEasyNetQLogger>(),
                    x.Resolve<Func<string>>(),
                    x.Resolve<IMessageValidationStrategy>()))
                .Register<IBus>(x => new RabbitBus(
                    x.Resolve<SerializeType>(),
                    x.Resolve<IEasyNetQLogger>(),
                    x.Resolve<IConventions>(),
                    x.Resolve<IAdvancedBus>()
                ));

            return serviceProvider;
        }
コード例 #2
0
        public static IBus CreateBus(IDefineRabbitQueue queue)
        {
            var connectionString = queue.Host;
            IConventions conventions = new Conventions(new TypeNameSerializer())
            {
                ExchangeNamingConvention = type => queue.ExchangeName,
                QueueNamingConvention = (type, info) => queue.QueueName,
                TopicNamingConvention = type => type.Name,
                ErrorExchangeNamingConvention = info => ErrorExchangeNameBasedOnEnvironment(queue),
                ErrorQueueNamingConvention = () => ErrorQueueNameBasedOnEnvironment(queue)
            };

            var bus = RabbitHutch.CreateBus(connectionString, x =>
            {
                x.Register(provider => conventions);
            });
            return bus;
        }
コード例 #3
0
ファイル: RabbitHutch.cs プロジェクト: negy/EasyNetQ
        /// <summary>
        /// Creates a new instance of RabbitBus
        /// </summary>
        /// <param name="hostName">
        /// The RabbitMQ broker.
        /// </param>
        /// <param name="virtualHost">
        /// The RabbitMQ virtualHost.
        /// </param>
        /// <param name="username">
        /// The username to use to connect to the RabbitMQ broker.
        /// </param>
        /// <param name="password">
        /// The password to use to connect to the RabbitMQ broker.
        /// </param>
        /// <param name="logger">
        /// The logger to use.
        /// </param>
        /// <returns>
        /// A new RabbitBus instance.
        /// </returns>
        public static IBus CreateBus(string hostName, string virtualHost, string username, string password, IEasyNetQLogger logger)
        {
            if(hostName == null)
            {
                throw new ArgumentNullException("hostName");
            }
            if(virtualHost == null)
            {
                throw new ArgumentNullException("virtualHost");
            }
            if(username == null)
            {
                throw new ArgumentNullException("username");
            }
            if(password == null)
            {
                throw new ArgumentNullException("password");
            }
            if(logger == null)
            {
                throw new ArgumentNullException("logger");
            }

            var connectionFactory = new ConnectionFactoryWrapper(new ConnectionFactory
            {
                HostName = hostName,
                VirtualHost = virtualHost,
                UserName = username,
                Password = password
            });

            var serializer = new JsonSerializer();

            var consumerErrorStrategy = new DefaultConsumerErrorStrategy(connectionFactory, serializer, logger);

            var conventions = new Conventions();

            var advancedBus = new RabbitAdvancedBus(
                connectionFactory,
                TypeNameSerializer.Serialize,
                serializer,
                new QueueingConsumerFactory(logger, consumerErrorStrategy),
                logger,
                CorrelationIdGenerator.GetCorrelationId,
                conventions);

            return new RabbitBus(
                TypeNameSerializer.Serialize,
                logger,
                conventions,
                advancedBus);
        }
コード例 #4
0
        public static IAdvancedBus CreateAdvancedBus(IDefineQueue queue)
        {
            var appSettings = new AppSettings();
            var connectionString = appSettings.ConnectionStrings.Get(queue.ConnectionStringKey, () => DefaultConnection);

            IConventions conventions = new Conventions(new TypeNameSerializer())
            {
                //ExchangeNamingConvention = type => queue.ExchangeName,
                //QueueNamingConvention = (type, information) => queue.QueueName,
                TopicNamingConvention = type => queue.ExchangeType, // type.Name,
                ErrorExchangeNamingConvention = information => queue.ErrorExchangeName,
                ErrorQueueNamingConvention = () => queue.ErrorQueueName
            };

            var bus = RabbitHutch.CreateBus(connectionString, x =>
            {
                x.Register(provider => conventions);
                x.Register<IEasyNetQLogger, RabbitMQLogger>();
            }).Advanced;
            return bus;
        }
コード例 #5
0
ファイル: RabbitHutch.cs プロジェクト: Hibame/EasyNetQ
        /// <summary>
        /// Creates a new instance of RabbitBus
        /// </summary>
        /// <param name="hostName">
        /// The RabbitMQ broker.
        /// </param>
        /// <param name="hostPort">
        /// The RabbitMQ broker port.
        /// </param>
        /// <param name="virtualHost">
        /// The RabbitMQ virtualHost.
        /// </param>
        /// <param name="username">
        /// The username to use to connect to the RabbitMQ broker.
        /// </param>
        /// <param name="password">
        /// The password to use to connect to the RabbitMQ broker.
        /// </param>
        /// <param name="logger">
        /// The logger to use.
        /// </param>
        /// <returns>
        /// A new RabbitBus instance.
        /// </returns>
        public static IBus CreateBus(string hostName, string hostPort, string virtualHost, string username, string password, IEasyNetQLogger logger)
        {
            if(hostName == null)
            {
                throw new ArgumentNullException("hostName");
            }
            if (hostPort == null)
            {
                throw new ArgumentNullException("hostPort");
            }
            if(virtualHost == null)
            {
                throw new ArgumentNullException("virtualHost");
            }
            if(username == null)
            {
                throw new ArgumentNullException("username");
            }
            if(password == null)
            {
                throw new ArgumentNullException("password");
            }
            if(logger == null)
            {
                throw new ArgumentNullException("logger");
            }

            var port = 0;
            if (!Int32.TryParse(hostPort, out port))
            {
                throw new FormatException("hostPort must be a valid 32-bit interger.");
            }

            var connectionFactory = new ConnectionFactoryWrapper(new ConnectionFactory
            {
                HostName = hostName,
                Port = port,
                VirtualHost = virtualHost,
                UserName = username,
                Password = password
            });

            var serializer = new JsonSerializer();

            var consumerErrorStrategy = new DefaultConsumerErrorStrategy(connectionFactory, serializer, logger);

            var conventions = new Conventions();

            return new RabbitBus(
                TypeNameSerializer.Serialize,
                serializer,
                new QueueingConsumerFactory(logger, consumerErrorStrategy),
                connectionFactory,
                logger,
                CorrelationIdGenerator.GetCorrelationId,
                conventions);
        }
コード例 #6
-2
        public void Configuration(IAppBuilder app)
        {
            app.MapSignalR();
            app.UseNancy();

            var bus = RabbitHutch.CreateBus("localhost");
            var conventions = new Conventions(new TypeNameSerializer());
            var subscriber = new AdvancedAutoSubscriber("prefix", bus, conventions)
            {
                SubscriptionConfiguration = (c, s) => c.WithAutoDelete()
            };
        }