Exemplo n.º 1
0
        private async Task <List <MessageRoute> > compileRoutes(Type messageType)
        {
            var list = new List <MessageRoute>();

            var modelWriter = _serializers.WriterFor(messageType);
            var supported   = modelWriter.ContentTypes;

            foreach (var channel in _channels.AllKnownChannels().Where(x => x.ShouldSendMessage(messageType)))
            {
                var contentType = supported.FirstOrDefault(x => x != "application/json") ?? "application/json";

                if (contentType.IsNotEmpty())
                {
                    list.Add(new MessageRoute(messageType, modelWriter, channel, contentType)
                    {
                    });
                }
            }

            var subscriptions = await _subscriptions.GetSubscribersFor(messageType);

            if (subscriptions.Any())
            {
                var published = new PublishedMessage(messageType, modelWriter, _channels);


                foreach (var subscription in subscriptions)
                {
                    if (MessageRoute.TryToRoute(published, subscription, out MessageRoute route,
                                                out PublisherSubscriberMismatch mismatch))
                    {
                        route.Writer  = modelWriter[route.ContentType];
                        route.Channel = _channels.GetOrBuildChannel(route.Destination);
                        list.Add(route);
                    }
                    else
                    {
                        _logger.SubscriptionMismatch(mismatch);
                    }
                }