コード例 #1
0
        public async Task GenerateReport(UserReportRequest request)
        {
            var consumers = new List <IDataConsumer <User> >()
            {
                new FindUserById(request.UserId),
                new GetUserNamesByAge(request.UserAge).SetMaxResultLines(50),
                new CalculateGenderByAge()
            };

            var success = await _producerFactory.GetProducer(request)
                          .AddConsumer(consumers)
                          .ProcessData(request)
                          .ConfigureAwait(false);

            if (success)
            {
                PrintResults(consumers);
            }
        }
コード例 #2
0
        /// <summary>
        /// Sends the specified event to the message broker on the specified topic.
        /// </summary>
        /// <param name="sentEvent">The event to be sent</param>
        /// <param name="topic">The destination topic</param>
        public async Task Send(IEvent sentEvent, string topic)
        {
            if (sentEvent == null)
            {
                throw new ArgumentNullException(nameof(sentEvent));
            }

            if (string.IsNullOrEmpty(topic))
            {
                throw new ArgumentNullException(nameof(topic));
            }

            var message = GetMessage(sentEvent);

            try {
                await producerFactory.GetProducer().ProduceAsync(topic, message);

                logger.LogInformation($"{nameof (Producer)}: message sent on topic <{topic}>: ", sentEvent);
            } catch (ProduceException <Null, string> e) {
                logger.LogError(e.ToString());
                throw new ArgumentException(e.Error.Reason);
            }
        }
コード例 #3
0
        private void StartSchedule(IProducerFactory producerFactory, IConsumerFactory consumerFactory, CancellationToken token)
        {
            var producers     = Enumerable.Range(0, this.Configuration.ProducerCount).Select(_ => producerFactory.GetProducer()).ToList();
            var consumers     = Enumerable.Range(0, this.Configuration.ConsumerCount).Select(_ => consumerFactory.GetConsumer()).ToList();
            var alsoConsumers = producers.Where(x => x is IConsumer).Select(x => x as IConsumer).ToList();
            var alsoProducers = consumers.Where(x => x is IProducer).Select(x => x as IProducer).ToList();

            if (this.logger != null)
            {
                this.logger.LogInformation($"{this.LogName}: {producers.Count} Producers has created!");
                this.logger.LogInformation($"{this.LogName}: {consumers.Count} Consumers has created!");
                if (alsoConsumers.Count > 0 || alsoProducers.Count > 0)
                {
                    var count = alsoConsumers.Count + alsoProducers.Count;
                    this.logger.LogInformation($"{this.LogName}: {count} detected as both and added!");
                }
            }

            this.producers = producers.Concat(alsoProducers);
            this.consumers = consumers.Concat(alsoConsumers);
            this.Schedule(token);
        }