Exemplo n.º 1
0
        public async Task <MessageRoute> RouteForDestination(Envelope envelope)
        {
            envelope.Destination = _lookup.Resolve(envelope.Destination);

            var messageType = envelope.Message.GetType();
            var routes      = await Route(messageType);

            var candidate = routes.FirstOrDefault(x => x.MatchesEnvelope(envelope));

            if (candidate != null)
            {
                return(candidate);
            }


            var modelWriter = _serializers.WriterFor(messageType);
            var contentType = envelope.ContentType ?? envelope.AcceptedContentTypes.Intersect(modelWriter.ContentTypes).FirstOrDefault()
                              ?? "application/json";


            var channel = _channels.GetOrBuildChannel(envelope.Destination);

            return(new MessageRoute(
                       messageType,
                       modelWriter,
                       channel,
                       contentType));
        }
Exemplo n.º 2
0
        public IChannel GetOrBuildChannel(Uri address)
        {
            var uri = _lookups == null ? address : _lookups.Resolve(address);

            assertValidTransport(uri);

            return(_channels.GetOrAdd(uri, u => new Lazy <IChannel>(() => buildChannel(u))).Value);
        }
Exemplo n.º 3
0
        public async Task ApplyLookups(UriAliasLookup lookups)
        {
            var all = Subscriptions.Select(x => x.Destination).Where(x => x != null).Distinct().ToArray();
            await lookups.ReadAliases(all);

            foreach (var subscription in Subscriptions.Where(x => x.Destination != null))
            {
                subscription.Destination = lookups.Resolve(subscription.Destination);
            }
        }
Exemplo n.º 4
0
        public void ReadAlias(UriAliasLookup lookups)
        {
            var real = lookups.Resolve(Uri);

            if (real != Uri)
            {
                Alias = Uri;
                Uri   = real;
            }
        }
Exemplo n.º 5
0
        public IChannel GetOrBuildChannel(Uri address)
        {
            var uri = _lookups == null ? address : _lookups.Resolve(address);

            assertValidTransport(uri);

            if (_channels.TryFind(uri, out var channel))
            {
                return(channel);
            }

            lock (_channelLock)
            {
                if (!_channels.TryFind(uri, out channel))
                {
                    channel   = buildChannel(address);
                    _channels = _channels.AddOrUpdate(address, channel);
                }

                return(channel);
            }
        }
Exemplo n.º 6
0
 public void ReadAlias(UriAliasLookup lookups)
 {
     Uri = lookups.Resolve(Uri);
 }