question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Changing topic in subscription interceptor is not working

See original GitHub issue

Hi,

I am having a MQTTnet broker/server which provides MQTT service to multiple teams and each team has its own users, devices, topics, …

First idea is to force the devices to publish/subscribe to a unique topic like: > /team_name/device_label

Another idea came to my mind: instead of forcing devices to set a unique topic in the whole broker to be separated in multiple teams, I prefer the topic to be defined by user freely and unique in its own team, like: /device_label

I tried to change the topic with WithApplicationMessageInterceptor on application message published to set the topic internally in the broker and it is working.

Then I tried to do the same on subscription with WithSubscriptionInterceptor, but it is not connecting to the defined topic.

Here is the simplified code and I am testing with MQTTBox as client:

static async Task Main(string[] args)
        {
            var optionsBuilder = new MqttServerOptionsBuilder()
                                    .WithDefaultEndpoint()
                                    .WithApplicationMessageInterceptor(ctx =>
                                    {
                                        ctx.ApplicationMessage.Topic = "abc";
                                        ctx.AcceptPublish = true;
                                        ctx.CloseConnection = false;
                                    })
                                    .WithSubscriptionInterceptor(ctx =>
                                    {
                                        ctx.TopicFilter.Topic = "abc";
                                        ctx.AcceptSubscription = true;
                                        ctx.CloseConnection = false;
                                    })
                                    .WithDefaultEndpointPort(1883);


            var mqttServer = new MqttFactory().CreateMqttServer();
            await mqttServer.StartAsync(optionsBuilder.Build());
            Console.WriteLine("Press any key to exit.");
            Console.ReadLine();
            await mqttServer.StopAsync();
        }

As you see, if you publish in ANY topic, it will be published in abc topic. But, the subscribers are not able to subscribe to abc topic.

Am I doing wrong, or my approach is not correct, or there is an issue in broker?

Thanks

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
chkr1011commented, Jun 7, 2019

Hi, this was not intended to work in that way. The only reason why this is possible at all is that the topic property of the topic filter is not immutable so you can set it to a different value.

But I got your point and it is quite easy to support it properly. So I will make this an official feature 😄 I will release this in the next version 3.0.3.

Best regards Christian

0reactions
chkr1011commented, Jul 12, 2022

Please test with latest version 4.0 and reopen this ticket if the issue still persists. Please also create a proper Unit Tests so that reproducing this issue is easier for all.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Changing topic in subscription interceptor is not working
Hi, I am having a MQTTnet broker/server which provides MQTT service to multiple teams and each team has its own users, devices, topics,...
Read more >
Interceptor not intercepting http requests (Angular 6)
In my case the HttpClient was not used to do the requests. Instead fetch has been used directly and that is not intercepted...
Read more >
That's why your Angular Interceptor may NOT WORK! 😥 [5 ...
EDIT : This problem does not occur when you import HttpClientModule only ONCE in the AppModule or CoreModule (and import the CoreModule into ......
Read more >
Interceptor URL isn't working as expected
Solved: G'day all, My requirement is as soon as I click on New Task Action button it should redirect to Interceptor.
Read more >
Angular Interceptors to Manage HTTP Requests ⚡
Learn how to use Angular interceptors to manage HTTP requests including JWT authorization , caching and logging.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found