diff --git a/Source/MQTTnet.Server/Controllers/ClientsController.cs b/Source/MQTTnet.Server/Controllers/ClientsController.cs index 6898375..bd9795a 100644 --- a/Source/MQTTnet.Server/Controllers/ClientsController.cs +++ b/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; diff --git a/Source/MQTTnet.Server/Controllers/MessagesController.cs b/Source/MQTTnet.Server/Controllers/MessagesController.cs new file mode 100644 index 0000000..89eb385 --- /dev/null +++ b/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 PostMessage(MqttApplicationMessage message) + { + await _mqttServerService.PublishAsync(message); + return Ok(); + } + + [Route("api/v1/messages/{*topic}")] + [HttpPost] + public Task PostMessage(string topic, string payload) + { + var message = new MqttApplicationMessageBuilder() + .WithTopic(topic) + .WithPayload(payload) + .Build(); + + return PostMessage(message); + } + } +} diff --git a/Source/MQTTnet.Server/Controllers/RetainedApplicationMessagesController.cs b/Source/MQTTnet.Server/Controllers/RetainedApplicationMessagesController.cs index 9c9f273..030d141 100644 --- a/Source/MQTTnet.Server/Controllers/RetainedApplicationMessagesController.cs +++ b/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; diff --git a/Source/MQTTnet.Server/Controllers/SessionsController.cs b/Source/MQTTnet.Server/Controllers/SessionsController.cs index 463c004..5fd0638 100644 --- a/Source/MQTTnet.Server/Controllers/SessionsController.cs +++ b/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;