コード例 #1
0
        public async Task ProcessSubscription(Subscription subscription)
        {
            if (subscription.SentBy.Contains(BrokerId))
            {
                return;
            }

            logger.LogInformation($"Received subscription: {subscription.Id} {subscription.Item}");

            if (settings.Items.Any(i => i == subscription.Item))
            {
                await statisticsDataSender.SendAsync(subscription.ToItemModel(true, settings.Name));

                logger.LogInformation($"Storing subscription: {subscription.Id} {subscription.Item}");

                await subscriptionsService.Add(subscription);
            }
            else if (settings.Peers != null)
            {
                subscription.SentBy.Add(BrokerId);

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

                foreach (var peer in settings.Peers)
                {
                    logger.LogInformation($"Sending subscription: {subscription.Id} {subscription.Item} to brokers: {string.Join(", ", settings.Peers)}");
                    RequestsSender.Subscriptions.Push(new RequestEnvelope <Subscription>
                    {
                        Resource    = subscription,
                        Destination = peer + "/subscriptions"
                    });
                }
            }
        }