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.

ApplicationMessageReceived isn't Async

See original GitHub issue

ApplicationMessageReceived isn’t Async which breaks the async flow and requires the event implementation to do .GetAwaiter().GetResult();.

Consider adding the ability to register a Func<Task> to flow the async context and also the cancellation token.

var mqttOptions = new MqttClientOptionsBuilder()
    //...
    .WithApplicationMessageReceiver(MyReceiver)  //   WithApplicationMessageReceiver(Func<MqttApplicationMessage, CancellationToken, Task>)
    //...
    .Build();
Task MyReceiver(MqttApplicationMessage message, CancellationToken cancellationToken)
{
     // Do async stuff
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
dpsennercommented, Feb 20, 2019

On the develop branch the ApplicationMessageReceived event is deprecated and there is an alternative and MQTTnet does now call the ReceivedApplicationMessageHandler and awaits that handler. That makes the api async, but the internals of MQTTnet are not async yet. This issue overlaps with the discussion we had in the PR #550. I now created #556 to discuss and track those changes.

0reactions
behroozbccommented, Nov 1, 2021

hi @chkr1011 I think is feature is implemented and should close this issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - How to receive published message when mqtt async ...
In Publish button, i have written code to publish the message and in mosquitto cmd prompt, i can receive the message. In viceversa,...
Read more >
Publish from MessageReceivedHandler doesn't work #648
When I Publish message from handler client.UseApplicationMessageReceivedHandler(async e => { await client.PublishAsync(message); }); I am ...
Read more >
Understanding Control Flow with Async and Await in C# | ...
This refers to the situation where you do not want to await an asynchronous method and you're not particularly concerned about when it...
Read more >
Asynchronous message-based communication
Since it's a message-based communication, the client assumes that the reply won't be received immediately, and that there might be no response ...
Read more >
Sending Asynchronous Messages
Send an asynchronous request using the tpacall() function. Get an asynchronous reply using the tpgetrply() function. The type of asynchronous processing ...
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