Exemple #1
0
        public async Task ProcessPublication(Publication publication)
        {
            if (publication.SentBy.Contains(BrokerId))
            {
                return;
            }

            await statisticsDataSender.SendAsync(publication.ToItemModel(false, settings.Name));

            logger.LogInformation($"Received publication: {publication.Id} {publication.Item}");
            if (settings.Items.Any(i => i == publication.Item))
            {
                var subscriptions = (await subscriptionsService.Get())
                                    .Where(s => s.Item == publication.Item).ToList();
                var fullfilledSubscriptions = await GetFullfilledSubscriptions(subscriptions, publication);

                var urls = fullfilledSubscriptions.Select(s => s.Url).Distinct();

                logger.LogInformation($"Sending publication: {publication.Id} {publication.Item} to subscribers: {string.Join(", ", urls)}");

                foreach (var url in urls)
                {
                    RequestsSender.Publications.Push(new RequestEnvelope <Publication>
                    {
                        Resource    = publication,
                        Destination = url
                    });
                }
            }
            else if (settings.Peers != null)
            {
                publication.SentBy.Add(BrokerId);
                foreach (var peer in settings.Peers)
                {
                    logger.LogInformation($"Sending publication: {publication.Id} {publication.Item} to brokers: {string.Join(", ", settings.Peers)}");
                    RequestsSender.Publications.Push(new RequestEnvelope <Publication>
                    {
                        Resource    = publication,
                        Destination = peer + "/publications"
                    });
                }
            }
        }