Skip to content

Commit

Permalink
fix: support symbols in mocked mqtt topic names
Browse files Browse the repository at this point in the history
  • Loading branch information
BEagle1984 committed Jul 21, 2022
1 parent 44aca09 commit 55693cd
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup Label="Package information">
<BaseVersionSuffix></BaseVersionSuffix>
<BaseVersion>3.7.2$(BaseVersionSuffix)</BaseVersion>
<BaseVersion>3.7.3$(BaseVersionSuffix)</BaseVersion>
<DatabasePackagesRevision>1</DatabasePackagesRevision>
<DatabasePackagesVersionSuffix>$(BaseVersionSuffix)</DatabasePackagesVersionSuffix>
</PropertyGroup>
Expand Down
6 changes: 6 additions & 0 deletions docs/releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ uid: releases

# Releases

## [3.7.3](https://github.com/BEagle1984/silverback/releases/tag/v3.7.3)

### Fixes

* Support topic names with symbols (e.g. hyphens) in mocked MQTT broker

## [3.7.2](https://github.com/BEagle1984/silverback/releases/tag/v3.7.2)

### Fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ private static bool IsSharedSubscription(
private static Regex GetSubscriptionRegex(string topic, IMqttClientOptions clientOptions)
{
var pattern = Regex.Escape(GetFullTopicName(topic, clientOptions))
.Replace("\\+", "[\\w]*", StringComparison.Ordinal)
.Replace("\\#", "[\\w\\/]*", StringComparison.Ordinal);
.Replace("\\+", "[^\\/]*", StringComparison.Ordinal)
.Replace("\\#", ".*", StringComparison.Ordinal);

return new Regex($"^{pattern}$", RegexOptions.Compiled);
}
Expand Down
30 changes: 30 additions & 0 deletions tests/Silverback.Integration.Tests.E2E/Mqtt/SubscriptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,35 @@ await publisher.PublishAsync(
.Select(envelope => ((TestEventOne)envelope.Message!).Content)
.Should().BeEquivalentTo(Enumerable.Range(1, 15).Select(i => $"{i}"));
}

[Fact]
public async Task Subscription_WithSymbolsInTopicName_MessagesConsumed()
{
Host.ConfigureServices(
services => services
.AddLogging()
.AddSilverback()
.UseModel()
.WithConnectionToMessageBroker(options => options.AddMockedMqtt())
.AddMqttEndpoints(
endpoints => endpoints
.Configure(
config => config
.ConnectViaTcp("e2e-mqtt-broker"))
.AddOutbound<TestEventOne>(endpoint => endpoint.ProduceTo("test/some-topic?name"))
.AddInbound(endpoint => endpoint.ConsumeFrom("test/+").Configure(config => config.WithClientId("e2e-test-1")))
.AddInbound(endpoint => endpoint.ConsumeFrom("test/#").Configure(config => config.WithClientId("e2e-test-2"))))
.AddIntegrationSpyAndSubscriber())
.Run();

var publisher = Host.ScopedServiceProvider.GetRequiredService<IEventPublisher>();

await publisher.PublishAsync(new TestEventOne());

await Helper.WaitUntilAllMessagesAreConsumedAsync();

Helper.Spy.OutboundEnvelopes.Should().HaveCount(1);
Helper.Spy.InboundEnvelopes.Should().HaveCount(2);
}
}
}

0 comments on commit 55693cd

Please sign in to comment.