public void replace_connection() { var uri = new TransportUri("rabbitmq://conn1/topic/foo"); var uri2 = uri.ReplaceConnection("conn2"); uri2.ToUri().ShouldBe("rabbitmq://conn2/topic/foo".ToUri()); }
private RabbitMqEndpoint(TransportUri uri, IRabbitMqProtocol protocol, ConnectionFactory factory, string exchangeName, ExchangeType exchangeType) : base(uri, protocol) { ConnectionFactory = factory; ExchangeName = exchangeName; ExchangeType = exchangeType; TransportUri = uri; }
public RabbitMqEndpoint(TransportUri uri, string connectionString) : base(uri, new DefaultRabbitMqProtocol()) { if (uri.Protocol != "rabbitmq") { throw new ArgumentOutOfRangeException(nameof(uri), "The protocol must be 'rabbitmq'"); } if (uri.QueueName.IsEmpty()) { throw new ArgumentOutOfRangeException(nameof(uri), "A queue name is required for Rabbit MQ endpoints"); } Port = 5672; TransportUri = uri; var parts = connectionString.Trim(';').ToDelimitedArray(';'); foreach (var part in parts) { var keyValues = part.Split('='); if (keyValues.Length != 2) { throw new ArgumentOutOfRangeException(nameof(connectionString), "The connection string is malformed"); } var key = keyValues[0]; var value = keyValues[1]; if (key.EqualsIgnoreCase(nameof(Host))) { Host = value; } else if (key.EqualsIgnoreCase(nameof(Port))) { Port = int.Parse(value); } else if (key.EqualsIgnoreCase(nameof(ExchangeName))) { ExchangeName = value; } else if (key.EqualsIgnoreCase(nameof(ExchangeType))) { ExchangeType = (ExchangeType)Enum.Parse(typeof(ExchangeType), value, true); } else { throw new ArgumentOutOfRangeException(nameof(connectionString), $"Unknown connection string parameter '{key}'"); } } if (Host.IsEmpty()) { throw new ArgumentOutOfRangeException(nameof(connectionString), "Host is required, but not specified"); } }
public void read_uri(string uriString, string protocol, string connectionName, string queue, string topic, bool durable) { var uri = new TransportUri(uriString); uri.Protocol.ShouldBe(protocol); uri.ConnectionName.ShouldBe(connectionName); uri.QueueName.ShouldBe(queue); uri.TopicName.ShouldBe(topic); uri.Durable.ShouldBe(durable); }
public RabbitMqMessageSpecificTopicListeningAgent(RabbitMqEndpoint endpoint, HandlerGraph handlers, TransportUri transportUri, ITransportLogger logger, JasperOptions settings) { Address = endpoint.Uri.ToUri(); var endpoints = endpoint.SpreadForMessageSpecificTopics(handlers.ValidMessageTypeNames()); foreach (var topicEndpoint in endpoints) { topicEndpoint.Connect(); var agent = topicEndpoint.CreateListeningAgent(transportUri.ToUri(), settings, logger); _inner.Add(agent); } }
public RabbitMqEndpoint[] SpreadForMessageSpecificTopics(string[] topicNames) { if (!Uri.IsMessageSpecificTopic()) { throw new InvalidOperationException($"{TransportUri.ToUri()} is not a message specific topic Uri"); } return(topicNames.Select(topic => { var uri = TransportUri.CloneForTopic(topic); var endpoint = new RabbitMqEndpoint(uri, Protocol, ConnectionFactory, ExchangeName, ExchangeType); endpoint.AmqpTcpEndpoints.AddRange(AmqpTcpEndpoints); return endpoint; }).ToArray()); }
protected override IListeningAgent buildListeningAgent(TransportUri transportUri, RabbitMqEndpoint endpoint, JasperOptions settings, HandlerGraph handlers) { if (endpoint == null) { throw new ArgumentOutOfRangeException(nameof(transportUri), $"Could not resolve a Rabbit MQ endpoint for the Uri '{transportUri}'"); } if (transportUri.IsMessageSpecificTopic()) { return(new RabbitMqMessageSpecificTopicListeningAgent(endpoint, handlers, transportUri, logger, settings)); } else { endpoint.Connect(); return(endpoint.CreateListeningAgent(transportUri.ToUri(), settings, logger)); } }
public void clone_for_topic() { var uri = new TransportUri( "rabbitmq", "conn1", true, "queue1", "*", "subscription1", "routingKey1"); var clone = uri.CloneForTopic("topic1"); clone.Protocol.ShouldBe(uri.Protocol); clone.ConnectionName.ShouldBe(uri.ConnectionName); clone.Durable.ShouldBe(uri.Durable); clone.QueueName.ShouldBe(uri.QueueName); clone.SubscriptionName.ShouldBe(uri.SubscriptionName); clone.RoutingKey.ShouldBe(uri.RoutingKey); clone.TopicName.ShouldBe("topic1"); }
protected override ISender buildSender(TransportUri transportUri, RabbitMqEndpoint endpoint, CancellationToken cancellation) { endpoint.Connect(); return(endpoint.CreateSender(logger, cancellation)); }
public AzureServiceBusEndpoint(TransportUri uri, string connectionString) : base(uri, new DefaultAzureServiceBusProtocol()) { ConnectionString = connectionString; }
public void read_subscription() { var uri = new TransportUri("azureservicebus://conn1/subscription/one"); uri.SubscriptionName.ShouldBe("one"); }
protected override ISender buildSender(TransportUri transportUri, AzureServiceBusEndpoint endpoint, CancellationToken cancellation) { return(new AzureServiceBusSender(endpoint, logger, cancellation)); }
protected override IListeningAgent buildListeningAgent(TransportUri transportUri, AzureServiceBusEndpoint endpoint, JasperOptions settings, HandlerGraph handlers) { return(new AzureServiceBusListeningAgent(endpoint, handlers, logger, settings.Cancellation)); }
public void generate_uri(string uriString, string protocol, string connectionName, string queue, string topic, bool durable) { var uri = new TransportUri(protocol, connectionName, durable, queueName: queue, topicName: topic); uri.ToUri().ShouldBe(uriString.ToUri()); }
protected override AzureServiceBusEndpoint buildEndpoint(TransportUri uri, string connectionString) { return(new AzureServiceBusEndpoint(uri, connectionString)); }
protected override RabbitMqEndpoint buildEndpoint(TransportUri uri, string connectionString) { return(new RabbitMqEndpoint(uri, connectionString)); }
public void write_uri_with_subscription() { var uri = new TransportUri("azureservicebus", "conn1", true, subscriptionName: "one"); uri.ToUri().ShouldBe(new Uri("azureservicebus://conn1/durable/subscription/one")); }
public void write_uri_with_routingkey() { var uri = new TransportUri("rabbitmq", "conn1", true, routingKey: "routing1"); uri.ToUri().ShouldBe(new Uri("rabbitmq://conn1/durable/routingkey/routing1")); }