/// <inheritdoc /> public virtual IEndpoint this[EndpointName endpointName] { get { if (!_endpoints.TryGetValue(endpointName, out IEndpoint endpoint)) { throw new EndpointNotFoundException(endpointName); } return(endpoint); } }
/// <summary> /// Adds a named endpoint to the collection /// </summary> /// <param name="endpointName">The name of the endpoint</param> /// <param name="endpoint">The endpoint</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="endpointName"/> /// or <paramref name="endpoint"/> are <c>null</c></exception> /// <exception cref="EndpointAlreadyExistsException">Thrown if there is already an /// endpoint with the specified <paramref name="endpointName"/></exception> public virtual void Add(EndpointName endpointName, IEndpoint endpoint) { if (endpointName == null) { throw new ArgumentNullException(nameof(endpointName)); } if (_endpoints.ContainsKey(endpointName)) { throw new EndpointAlreadyExistsException(endpointName); } _endpoints[endpointName] = endpoint ?? throw new ArgumentNullException(nameof(endpoint)); }
/// <inheritdoc /> public Task <ISentMessage> Send(object content, EndpointName endpointName, SendOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { CheckDisposed(); if (content == null) { throw new ArgumentNullException(nameof(content)); } if (endpointName == null) { throw new ArgumentNullException(nameof(endpointName)); } var myOptions = options ?? _defaultSendOptions; var endpoint = _endpoints[endpointName]; var credentials = endpoint.Credentials; if (myOptions.Credentials != null) { credentials = myOptions.Credentials; } var headers = new MessageHeaders { Destination = endpoint.Address, Sent = DateTime.UtcNow }; var message = BuildMessage(content, headers, myOptions); // Create the sent message before transporting it in order to ensure that the // reply stream is cached before any replies arrive. var sentMessage = _replyHub.CreateSentMessage(message); var sentMessageSource = SendMessage(message, credentials, cancellationToken) .GetCompletionSource(sentMessage, cancellationToken); _diagnosticService.Emit(new DiagnosticEventBuilder(this, DiagnosticEventType.MessageSent) { Message = message, Endpoint = endpointName }.Build()); return(sentMessageSource.Task); }
public LoopbackEndpoints(EndpointName name, Uri baseUri) { _baseUri = baseUri ?? throw new ArgumentNullException(nameof(baseUri)); base.Add(name, new Endpoint(baseUri)); }
public override bool Contains(EndpointName endpointName) { return(true); }
public override IEndpoint this[EndpointName endpointName] => new Endpoint(_baseUri);
public override void Add(EndpointName endpointName, IEndpoint endpoint) { }
/// <inheritdoc /> public virtual bool Contains(EndpointName endpointName) { return(_endpoints.ContainsKey(endpointName)); }
/// <summary> /// Initializes a new <see cref="EndpointNotFoundException"/> for the /// specified <paramref name="endpoint"/> name /// </summary> /// <param name="endpoint">The name of the endpoint that could not be /// found</param> public EndpointNotFoundException(EndpointName endpoint) : base(endpoint) { Endpoint = endpoint; }