예제 #1
0
        private static IBusControl ConfigureRabbitMQ(IBusRegistrationContext context)
        {
            IRabbitMQConfig config = context.GetRequiredService <IRabbitMQConfig>();

            var bus = Bus.Factory.CreateUsingRabbitMq(cfg =>
            {
                // cfg.UseHealthCheck(context);
                cfg.Host(config.Host, config.VirtualHost, rmqHost =>
                {
                    rmqHost.Username(config.UserName);
                    rmqHost.Password(config.Password);
                });

                cfg.ReceiveEndpoint(config.Endpoint, rmqEndpoint =>
                {
                    rmqEndpoint.PrefetchCount = config.PrefetchCount;
                    rmqEndpoint.Durable       = config.DurableQueue;
                    rmqEndpoint.ConfigureConsumer <RegistrationSuccessfulConsumer>(context);
                });
            });

            bus.Start();

            return(bus);
        }
예제 #2
0
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="config">配置文件</param>
        /// <param name="connectionNumber">链接数量</param>
        /// <param name="channelNumber">通道数量</param>
        /// <param name="channelAction">通道处理</param>
        protected BaseRabbitMQHelper(IRabbitMQConfig config, int connectionNumber, int channelNumber, Action <IModel> channelAction = null)
        {
            MQConfig    = config;
            Connections = new Dictionary <IConnection, List <IModel> >();
            var factory = new ConnectionFactory {
                HostName = MQConfig.HostName
            };

            for (int i = 0; i < connectionNumber; i++)
            {
                IConnection connection = factory.CreateConnection();
                var         channels   = new List <IModel>();
                for (int j = 0; j < channelNumber; j++)
                {
                    IModel channel = connection.CreateModel();
                    if (MQConfig.Durable)
                    {
                        IBasicProperties properties = channel.CreateBasicProperties();
                        properties.Persistent = true;
                    }
                    if (j == 0)
                    {
                        channel.ExchangeDeclare(MQConfig.ExchangeName, MQConfig.ExchangeCategoryString, MQConfig.Durable, MQConfig.AutoDelete, null);
                        channel.QueueDeclare(MQConfig.QueueName, MQConfig.Durable, MQConfig.Exclusive, MQConfig.AutoDelete, null);
                        channel.QueueBind(MQConfig.QueueName, MQConfig.ExchangeName, config.RoutingKey);
                    }
                    channelAction?.Invoke(channel);
                    channels.Add(channel);
                }
                Connections[connection] = channels;
            }
        }
예제 #3
0
 public RabbitMQReceivingChannel(IChannelFactory cf, IRabbitMQConfig cfg) : base(cf)
 {
     this.cfg = cfg;
 }
 public SendMessageToEndpoint(ISendEndpointProvider sendEndpoint, IRabbitMQConfig config)
 {
     _sendEndpoint = sendEndpoint;
     _rabbitConfig = config;
 }
예제 #5
0
 public ChannelFactory(IRabbitMQConfig rabbitCfg, IBusConfig busCfg)
 {
     this.rabbitCfg = rabbitCfg;
     endpointName   = busCfg.EndpointName;
     CreateConnection();
 }
예제 #6
0
 public RabbitMQTransport(IRabbitMQConfig config, IHost host)
 {
     Config = config ?? throw new ArgumentNullException(nameof(config));
     Host   = host ?? throw new ArgumentNullException(nameof(host));
 }