Pārlūkot izejas kodu

MQTTnet.Server: Extend messages API.

release/3.x.x
Christian Kratky pirms 5 gadiem
vecāks
revīzija
6608172719
1 mainītis faili ar 13 papildinājumiem un 2 dzēšanām
  1. +13
    -2
      Source/MQTTnet.Server/Controllers/MessagesController.cs

+ 13
- 2
Source/MQTTnet.Server/Controllers/MessagesController.cs Parādīt failu

@@ -1,7 +1,9 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using MQTTnet.Protocol;
using MQTTnet.Server.Mqtt;

namespace MQTTnet.Server.Controllers
@@ -27,14 +29,23 @@ namespace MQTTnet.Server.Controllers

[Route("api/v1/messages/{*topic}")]
[HttpPost]
public Task<ActionResult> PostMessage(string topic, string payload)
public async Task<ActionResult> PostMessage(string topic, int qosLevel = 0)
{
byte[] payload;

using (var memoryStream = new MemoryStream())
{
await HttpContext.Request.Body.CopyToAsync(memoryStream);
payload = memoryStream.ToArray();
}

var message = new MqttApplicationMessageBuilder()
.WithTopic(topic)
.WithPayload(payload)
.WithQualityOfServiceLevel((MqttQualityOfServiceLevel)qosLevel)
.Build();

return PostMessage(message);
return await PostMessage(message);
}
}
}

Notiek ielāde…
Atcelt
Saglabāt