/// <summary>
        /// Configure a specific endpoint
        /// </summary>
        /// <param name="uri"></param>
        /// <param name="alteration"></param>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        public void ConfigureEndpoint(TransportUri uri, Action <TEndpoint> alteration)
        {
            var endpoint = For(uri);

            if (endpoint == null)
            {
                throw new ArgumentOutOfRangeException(nameof(uri), $"Unknown connection named '{uri.ConnectionName}'");
            }

            alteration(endpoint);
        }
        protected override IListeningAgent buildListeningAgent(Uri uri, JasperOptions settings, HandlerGraph handlers)
        {
            var transportUri = new TransportUri(uri);
            var endpoint     = _options.For(transportUri);

            if (endpoint == null)
            {
                throw new ArgumentOutOfRangeException(nameof(uri), $"Unknown {Protocol} connection named '{transportUri.ConnectionName}'");
            }

            return(buildListeningAgent(transportUri, endpoint, settings, handlers));
        }
        protected sealed override ISender createSender(Uri uri, CancellationToken cancellation)
        {
            var transportUri = new TransportUri(uri);
            var endpoint     = _options.For(transportUri);

            if (endpoint == null)
            {
                throw new ArgumentOutOfRangeException(nameof(uri), $"Unknown {Protocol} connection named '{transportUri.ConnectionName}'");
            }


            return(buildSender(transportUri, endpoint, cancellation));
        }
        /// <summary>
        /// Try to resolve the endpoint for the given TransportUri
        /// </summary>
        /// <param name="uri"></param>
        /// <returns></returns>
        public TEndpoint For(TransportUri uri)
        {
            if (_endpoints.TryFind(uri, out var endpoint))
            {
                return(endpoint);
            }

            if (uri.Protocol != _protocol)
            {
                throw new ArgumentOutOfRangeException($"Invalid uri protocol '{uri.Protocol}', expected '{_protocol}'");
            }

            if (uri.TopicName.IsEmpty() && uri.QueueName.IsEmpty())
            {
                throw new ArgumentOutOfRangeException($"Invalid Azure Service Bus uri '{uri.ToUri()}'. Either 'topic' or 'queue' must be assigned");
            }

            var keys = uri.UriKeys();

            var invalids = keys.Where(x => !_validTransportUriKeys.Contains(x));

            if (invalids.Any())
            {
                throw new ArgumentOutOfRangeException($"Invalid {nameof(TransportUri)} value(s) for transport \"{uri.Protocol}\": {invalids.Join(", ")}");
            }

            lock (_locker)
            {
                if (_endpoints.TryFind(uri, out endpoint))
                {
                    return(endpoint);
                }

                if (!Connections.ContainsKey(uri.ConnectionName))
                {
                    return(null);
                }

                endpoint   = buildEndpoint(uri, Connections[uri.ConnectionName]);
                _endpoints = _endpoints.AddOrUpdate(uri, endpoint);

                return(endpoint);
            }
        }
Exemplo n.º 5
0
 protected bool Equals(TransportUri other)
 {
     return(string.Equals(Protocol, other.Protocol) && string.Equals(TopicName, other.TopicName) && string.Equals(QueueName, other.QueueName) && string.Equals(SubscriptionName, other.SubscriptionName) && string.Equals(ConnectionName, other.ConnectionName) && Durable == other.Durable);
 }
 protected abstract TEndpoint buildEndpoint(TransportUri uri, string connectionString);
Exemplo n.º 7
0
 public Endpoint(TransportUri uri, TProtocol protocol)
 {
     Uri       = uri;
     _protocol = protocol;
 }
 protected abstract IListeningAgent buildListeningAgent(TransportUri transportUri, TEndpoint endpoint,
                                                        JasperOptions settings, HandlerGraph handlers);
 protected abstract ISender buildSender(TransportUri transportUri, TEndpoint endpoint,
                                        CancellationToken cancellation);