Преглед изворни кода

MQTTnet.Server: Add HTTP API for publishing of messages.

release/3.x.x
Christian Kratky пре 5 година
родитељ
комит
019f428f0a
4 измењених фајлова са 43 додато и 3 уклоњено
  1. +1
    -1
      Source/MQTTnet.Server/Controllers/ClientsController.cs
  2. +40
    -0
      Source/MQTTnet.Server/Controllers/MessagesController.cs
  3. +1
    -1
      Source/MQTTnet.Server/Controllers/RetainedApplicationMessagesController.cs
  4. +1
    -1
      Source/MQTTnet.Server/Controllers/SessionsController.cs

+ 1
- 1
Source/MQTTnet.Server/Controllers/ClientsController.cs Прегледај датотеку

@@ -13,7 +13,7 @@ namespace MQTTnet.Server.Controllers
{
[Authorize]
[ApiController]
public class ClientsController : ControllerBase
public class ClientsController : Controller
{
private readonly MqttServerService _mqttServerService;



+ 40
- 0
Source/MQTTnet.Server/Controllers/MessagesController.cs Прегледај датотеку

@@ -0,0 +1,40 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using MQTTnet.Server.Mqtt;

namespace MQTTnet.Server.Controllers
{
[Authorize]
[ApiController]
public class MessagesController : Controller
{
private readonly MqttServerService _mqttServerService;

public MessagesController(MqttServerService mqttServerService)
{
_mqttServerService = mqttServerService ?? throw new ArgumentNullException(nameof(mqttServerService));
}

[Route("api/v1/messages")]
[HttpPost]
public async Task<ActionResult> PostMessage(MqttApplicationMessage message)
{
await _mqttServerService.PublishAsync(message);
return Ok();
}

[Route("api/v1/messages/{*topic}")]
[HttpPost]
public Task<ActionResult> PostMessage(string topic, string payload)
{
var message = new MqttApplicationMessageBuilder()
.WithTopic(topic)
.WithPayload(payload)
.Build();

return PostMessage(message);
}
}
}

+ 1
- 1
Source/MQTTnet.Server/Controllers/RetainedApplicationMessagesController.cs Прегледај датотеку

@@ -12,7 +12,7 @@ namespace MQTTnet.Server.Controllers
{
[Authorize]
[ApiController]
public class RetainedApplicationMessagesController : ControllerBase
public class RetainedApplicationMessagesController : Controller
{
private readonly MqttServerService _mqttServerService;



+ 1
- 1
Source/MQTTnet.Server/Controllers/SessionsController.cs Прегледај датотеку

@@ -13,7 +13,7 @@ namespace MQTTnet.Server.Controllers
{
[Authorize]
[ApiController]
public class SessionsController : ControllerBase
public class SessionsController : Controller
{
private readonly MqttServerService _mqttServerService;



Loading…
Откажи
Сачувај