-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
760 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -292,3 +292,5 @@ __pycache__/ | |
*.map | ||
|
||
/Tests/MQTTnet.TestApp.NetCore/RetainedMessages.json | ||
|
||
Build/NuGet/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
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 | ||
{ | ||
[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 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 await PostMessage(message); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using System.Reflection; | ||
|
||
namespace MQTTnet.Server.Controllers | ||
{ | ||
[Authorize] | ||
[ApiController] | ||
public class ServerController : Controller | ||
{ | ||
[Route("api/v1/server/version")] | ||
[HttpGet] | ||
public ActionResult<string> GetVersion() | ||
{ | ||
return Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.