Example #1
0
        public RabbitEventBus AddGrainConsumer <PrimaryKey>(string observerGroup)
        {
            var observerUnit = observerUnitContainer.GetUnit <PrimaryKey>(ProducerType);
            var consumer     = new RabbitConsumer(
                observerUnit.GetEventHandlers(observerGroup),
                observerUnit.GetBatchEventHandlers(observerGroup))
            {
                EventBus  = this,
                QueueList = RouteList.Select(route => new QueueInfo {
                    RoutingKey = route, Queue = $"{route}_{observerGroup}"
                }).ToList(),
                Config = ConsumerConfig
            };

            Consumers.Add(consumer);
            return(this);
        }
Example #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);
        }
Example #3
0
        public RabbitEventBus CreateConsumer <K>(string followType, ushort minQos = 100, ushort incQos = 100, ushort maxQos = 300, bool autoAck = false, bool errorReject = false)
        {
            var consumer = new RabbitConsumer(ServiceProvider.GetService <IFollowUnitContainer>().GetUnit <K>(ProducerType).GetEventHandlers(followType))
            {
                EventBus    = this,
                QueueList   = new List <QueueInfo>(),
                AutoAck     = autoAck,
                MaxQos      = maxQos,
                MinQos      = minQos,
                IncQos      = incQos,
                ErrorReject = errorReject
            };

            foreach (var route in RouteList)
            {
                consumer.QueueList.Add(new QueueInfo {
                    RoutingKey = route, Queue = $"{followType}_{route}"
                });
            }
            Consumers.Add(consumer);
            return(this);
        }
Example #4
0
        public RabbitEventBus AddConsumer(
            Func <byte[], Task> handler,
            Func <List <byte[]>, Task> batchHandler,
            string observerGroup)
        {
            var consumer = new RabbitConsumer(
                new List <Func <byte[], Task> > {
                handler
            },
                new List <Func <List <byte[]>, Task> > {
                batchHandler
            })
            {
                EventBus  = this,
                QueueList = RouteList.Select(route => new QueueInfo {
                    RoutingKey = route, Queue = $"{route}_{observerGroup}"
                }).ToList(),
                Config = ConsumerConfig
            };

            Consumers.Add(consumer);
            return(this);
        }