dotnet / dotnet/MQTTnet

Server: Is there an option in the server to just get the messages that you subscribed to before?

Open
#1,842 7 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
C#
Stars
5.1k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

### Describe your question
@chkr1011 Is there an option in the server to just get the messages that you subscribed to before? There is, of course, `InterceptingPublishAsync` which can be used like this, but this will get all messages that are published to the server.

```csharp
private async Task Run()
{
var mqttFactory = new MqttFactory();
var mqttServerOptions = new MqttServerOptionsBuilder().WithDefaultEndpoint().Build();

using (var mqttServer = mqttFactory.CreateMqttServer(mqttServerOptions))
{
await mqttServer.StartAsync();
mqttServer.InterceptingPublishAsync += this.InterceptPublish;
await mqttServer.SubscribeAsync("Test", "a/b/#");
await mqttServer.StopAsync();
}
}

private async Task InterceptPublish(InterceptingPublishEventArgs args)
{
// Handle some published data here.
args.ProcessPublish = true;
}
```

### Which project is your question related to?
- Server

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.