Esempio n. 1
0
 public RabbitEventBus(
     IServiceProvider serviceProvider,
     IRabbitEventBusContainer eventBusContainer,
     string exchange, string routePrefix, int lBCount = 1, ushort minQos = 100, ushort incQos = 100, ushort maxQos = 300, bool autoAck = false, bool reenqueue = false)
 {
     if (string.IsNullOrEmpty(exchange))
     {
         throw new ArgumentNullException(nameof(exchange));
     }
     if (string.IsNullOrEmpty(routePrefix))
     {
         throw new ArgumentNullException(nameof(routePrefix));
     }
     if (lBCount < 1)
     {
         throw new ArgumentOutOfRangeException($"{nameof(lBCount)} must be greater than 1");
     }
     ServiceProvider       = serviceProvider;
     observerUnitContainer = serviceProvider.GetService <IObserverUnitContainer>();
     Container             = eventBusContainer;
     Exchange              = exchange;
     RoutePrefix           = routePrefix;
     LBCount               = lBCount;
     DefaultConsumerConfig = new BranchOptions
     {
         AutoAck   = autoAck,
         MaxQos    = maxQos,
         MinQos    = minQos,
         IncQos    = incQos,
         Reenqueue = reenqueue
     };
     RouteList = new List <string>();
     if (LBCount == 1)
     {
         RouteList.Add(routePrefix);
     }
     else
     {
         for (int i = 0; i < LBCount; i++)
         {
             RouteList.Add($"{routePrefix }_{ i.ToString()}");
         }
     }
     _CHash = new ConsistentHash(RouteList, lBCount * 10);
 }
Esempio n. 2
0
        public RabbitEventBus CreateConsumer <PrimaryKey>(string observerGroup, BranchOptions consumerConfig = default)
        {
            var consumer = new RabbitConsumer(observerUnitContainer.GetUnit <PrimaryKey>(ProducerType).GetEventHandlers(observerGroup))
            {
                EventBus  = this,
                QueueList = new List <QueueInfo>(),
                Config    = consumerConfig == null || consumerConfig.MinQos == 0 ? DefaultConsumerConfig : consumerConfig
            };

            foreach (var route in RouteList)
            {
                consumer.QueueList.Add(new QueueInfo {
                    RoutingKey = route, Queue = $"{route}_{observerGroup}"
                });
            }
            Consumers.Add(consumer);
            return(this);
        }