Skip to content

Commit

Permalink
removed possibility to publish on multiple exchanges at the same time
Browse files Browse the repository at this point in the history
  • Loading branch information
hansehe committed Nov 26, 2018
1 parent 2048906 commit f6e3256
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
16 changes: 8 additions & 8 deletions Rebus.RabbitMq.Tests/RabbitMqCustomExchangeNamesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ public async Task CanUseAlternateCustomExchangeName()
const string connectionString = RabbitMqTransportFactory.ConnectionString;

var rabbitMqTransport = new RabbitMqTransport(connectionString, "inputQueue", new ConsoleLoggerFactory(false));


var defaultTopicExchange = "defaultTopicExchange";
rabbitMqTransport.AllowPublishOnAlternateExchanges();
rabbitMqTransport.SetTopicExchangeName(defaultTopicExchange);

var topic = "myTopic";
var alternateExchange = "alternateExchange";
Expand All @@ -71,14 +73,12 @@ public async Task CanUseAlternateCustomExchangeName()

var subscriberAddresses = await rabbitMqTransport.GetSubscriberAddresses(topicWithAlternateExchange);
Assert.That(subscriberAddresses[0], Is.EqualTo(topicWithAlternateExchange));

var topicWithMultipleAlternateExchanges = $"{topic}@{alternateExchange}@{alternateExchange}@{alternateExchange}";

subscriberAddresses = await rabbitMqTransport.GetSubscriberAddresses(topicWithMultipleAlternateExchanges);
foreach (var subscriberAddress in subscriberAddresses)
{
Assert.That(subscriberAddress, Is.EqualTo(topicWithAlternateExchange));
}
subscriberAddresses = await rabbitMqTransport.GetSubscriberAddresses(topic);
Assert.That(subscriberAddresses[0], Is.EqualTo($"{topic}@{defaultTopicExchange}"));

subscriberAddresses = await rabbitMqTransport.GetSubscriberAddresses(topic + '@');
Assert.That(subscriberAddresses[0], Is.EqualTo($"{topic}@@{defaultTopicExchange}"));
}
}
}
3 changes: 1 addition & 2 deletions Rebus.RabbitMq/Config/RabbitMqOptionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,9 @@ public RabbitMqOptionsBuilder EnablePublisherConfirms(bool value = true)
}

/// <summary>
/// Publish a topic on a single or multiple alternate exchanges.
/// Publish a topic on an alternate exchange.
/// Use the following syntax to publish a topic on an alternate exchange called "alternateExchange":
/// "topic@alternateExchange"
/// Publish on multiple exchanges by appending more exchanges separated with '@'.
/// </summary>
public RabbitMqOptionsBuilder AllowPublishOnAlternateExchanges(bool value = true)
{
Expand Down
13 changes: 3 additions & 10 deletions Rebus.RabbitMq/RabbitMq/RabbitMqTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,9 @@ public void EnablePublisherConfirms(bool value = true)
}

/// <summary>
/// Publish a topic on a single or multiple alternate exchanges.
/// Publish a topic on an alternate exchange.
/// Use the following syntax to publish a topic on an alternate exchange called "alternateExchange":
/// "topic@alternateExchange"
/// Publish on multiple exchanges by appending more exchanges separated with '@'.
/// </summary>
public void AllowPublishOnAlternateExchanges(bool value = true)
{
Expand Down Expand Up @@ -764,17 +763,11 @@ public async Task<string[]> GetSubscriberAddresses(string topic)
{
if (topic.Contains('@') && _allowPublishOnAlternateExchanges)
{
var subscriberAddresses = new List<string>();
var tokens = topic.Split('@');
topic = tokens[0];
for (var i = 1; i < tokens.Length; i++)
if (tokens.Last() != string.Empty)
{
subscriberAddresses.Add(tokens[i] == string.Empty
? $"{topic}@{_topicExchangeName}"
: $"{topic}@{tokens[i]}");
return new[] {topic};
}

return subscriberAddresses.ToArray();
}
return new[] { $"{topic}@{_topicExchangeName}" };
}
Expand Down

0 comments on commit f6e3256

Please sign in to comment.