Skip to content

Commit d998f25

Browse files
committed
Add sample controller with deserialization payload
1 parent 8300f2d commit d998f25

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Threading.Tasks;
2+
using Microsoft.Extensions.Logging;
3+
using MQTTnet.AspNetCore.Routing;
4+
using MQTTnet.AspNetCore.Routing.Attributes;
5+
6+
namespace ExampleServer.MqttControllers;
7+
8+
[MqttController]
9+
public class ViewModelController: MqttBaseController
10+
{
11+
private ILogger<ViewModelController> Logger { get; }
12+
13+
public ViewModelController(ILogger<ViewModelController> logger)
14+
{
15+
Logger = logger;
16+
}
17+
18+
[MqttRoute("viewmodel/{sender}")]
19+
public Task DeserializeViewModel(string sender, [FromPayload] SamplePayload payload)
20+
{
21+
Logger.LogInformation("{Sender} says {Message}", sender, payload.Message);
22+
return Accepted();
23+
}
24+
}
25+
26+
public class SamplePayload
27+
{
28+
public string Message { get; set; }
29+
}

0 commit comments

Comments
 (0)