-
-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MQTT wildcard listening. Closes GH-654
- Loading branch information
1 parent
1ce184e
commit 0f47842
Showing
3 changed files
with
102 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/Transports/MQTT/Wolverine.MQTT.Tests/listen_with_topic_wildcards.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using JasperFx.Core; | ||
using Microsoft.Extensions.Hosting; | ||
using Shouldly; | ||
using TestingSupport; | ||
using Wolverine.Tracking; | ||
using Xunit.Abstractions; | ||
|
||
namespace Wolverine.MQTT.Tests; | ||
|
||
public class listen_with_topic_wildcards : IAsyncLifetime | ||
{ | ||
private readonly ITestOutputHelper _output; | ||
private IHost _sender; | ||
private IHost _receiver; | ||
|
||
public listen_with_topic_wildcards(ITestOutputHelper output) | ||
{ | ||
_output = output; | ||
} | ||
|
||
public async Task InitializeAsync() | ||
{ | ||
var port = PortFinder.GetAvailablePort(); | ||
|
||
|
||
Broker = new LocalMqttBroker(port) | ||
{ | ||
Logger = new XUnitLogger( _output, "MQTT") | ||
}; | ||
|
||
await Broker.StartAsync(); | ||
|
||
_sender = await Host.CreateDefaultBuilder() | ||
.UseWolverine(opts => | ||
{ | ||
opts.UseMqttWithLocalBroker(port); | ||
opts.Policies.DisableConventionalLocalRouting(); | ||
}).StartAsync(); | ||
|
||
#region sample_listen_to_mqtt_topic_filter | ||
|
||
_receiver = await Host.CreateDefaultBuilder() | ||
.UseWolverine(opts => | ||
{ | ||
opts.UseMqttWithLocalBroker(port); | ||
opts.ListenToMqttTopic("incoming/#").RetainMessages(); | ||
}).StartAsync(); | ||
|
||
#endregion | ||
} | ||
|
||
[Fact] | ||
public async Task broadcast() | ||
{ | ||
var session = await _sender.TrackActivity() | ||
.AlsoTrack(_receiver) | ||
.Timeout(30.Seconds()) | ||
.ExecuteAndWaitAsync(m => m.BroadcastToTopicAsync("incoming/one", new ColorMessage("blue"))); | ||
|
||
var received = session.Received.SingleMessage<ColorMessage>(); | ||
received.Color.ShouldBe("blue"); | ||
} | ||
|
||
public LocalMqttBroker Broker { get; set; } | ||
|
||
public async Task DisposeAsync() | ||
{ | ||
await Broker.StopAsync(); | ||
await _sender.StopAsync(); | ||
await _receiver.StopAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters