MQTTnet ์†Œ๊ฐœ

dotnet/MQTTnet์€ MQTT ๊ธฐ๋ฐ˜ ํ†ต์‹ ์„ ์œ„ํ•œ ๊ณ ์„ฑ๋Šฅ .NET ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ MQTT์˜ ์ทจ์ง€์— ๋งž๊ฒŒ ๊ฒฝ๋Ÿ‰์ด๋ฉฐ ์ดˆ๋‹น 150,000๊ฐœ ์ˆ˜์ค€์˜ ๋ฉ”์‹œ์ง€๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” MQTT ํด๋ผ์ด์–ธํŠธ ๋ฐ MQTT ์„œ๋ฒ„(๋ธŒ๋กœ์ปค)๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

Azure Functions MQTT ๋ฐ”์ธ๋”ฉ์— ์“ฐ์ด๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ด๋ฉฐ .NET Foundation์—์„œ ์ง€์›ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

MQTT๋Š” ๋ฐœํ–‰-๊ตฌ๋… ๊ธฐ๋ฐ˜์˜ ๋ฉ”์‹œ์ง• ํ”„๋กœํ† ์ฝœ๋กœ IoTํ†ต์‹ ์— ๋งŽ์ด ์“ฐ์ž…๋‹ˆ๋‹ค. ๊ณต๊ฐœ๋œ MQTT ๋ธŒ๋กœ์ปค๊ฐ€ ๋งŽ์ด ์žˆ์œผ๋ฏ€๋กœ ๋ฉ”์‹œ์ง• ๊ธฐ๋Šฅ์„ ๊ฐ„๋‹จํ•˜๊ฒŒ ํ…Œ์ŠคํŠธํ•˜๊ธฐ๋„ ์šฉ์˜ํ•ฉ๋‹ˆ๋‹ค.

MQTTNet์€ ๋‹ค์Œ์˜ ์ฃผ์š” ํŠน์ง•์„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

  • ๋น„๋™๊ธฐ ์ง€์›
  • ํด๋ผ์ด์–ธํŠธ ๋ฐ ์„œ๋ฒ„์— ๋Œ€ํ•œ TLS ์ง€์›
  • ํ™•์žฅ ๊ฐ€๋Šฅํ•œ ํ†ต์‹  ์ฑ„๋„ (In-Memory, TCP, TCP+TLS, WS)
  • ๊ฒฝ๋Ÿ‰(์˜ค๋ฒ„ํ—ค๋“œ ์—†์Œ)
  • ์„ฑ๋Šฅ ์ตœ์ ํ™”(~150,000๊ฐœ ๋ฉ”์‹œ์ง€/์ดˆ ์ฒ˜๋ฆฌ)
  • ์ง€์›๋˜๋Š” ๋ชจ๋“  MQTT ํ”„๋กœํ† ์ฝœ ๋ฒ„์ ผ์— ๋Œ€ํ•œ ๋™์ผํ•œ API ์ œ๊ณต
  • ๋‚ด๋ถ€ ์ถ”์  ๋ฉ”์‹œ์ง€์— ๋Œ€ํ•œ ์•ก์„ธ์Šค
  • ๋‹จ์œ„ํ…Œ์ŠคํŠธ (~636 ํ…Œ์ŠคํŠธ)
  • ์™ธ๋ถ€ ์ข…์†์„ฑ ์—†์Œ

ํŠนํžˆ ์›น์†Œ์ผ“์„ ์ง€์›ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์›น์†Œ์ผ“์„ ์ œ๊ณตํ•˜๋Š” ๋ธŒ๋กœ์ปค๋ฅผ ์ด์šฉํ•ด ์›น๋ธŒ๋ผ์šฐ์ €์—์„œ๋„ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋ฉ”์‹œ์ง• ํ”„๋กœํ† ์ฝœ ์ž…๋‹ˆ๋‹ค.


์ข‹์•„์š” 5

๊นƒํ—ˆ๋ธŒ์˜ Samples๋ฅผ ํ†ตํ•ด ๊ฐ์ข… ์‚ฌ์šฉ๋ฒ•์„ ํ•™์Šตํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ์€ broker.hivemq.com MQTT ๋ธŒ๋กœ์ปค์— ์—ฐ๊ฒฐํ•œ ํ›„ ์ข…๋ฃŒํ•˜๋Š” ์ฝ”๋“œ ์ž…๋‹ˆ๋‹ค.

using MQTTnet;
using MQTTnet.Client.Options;

using System.Text.Json;
using MQTTnet.Client.Disconnecting;

var factory = new MqttFactory();
using var client = factory.CreateMqttClient();
var options = new MqttClientOptionsBuilder()
    .WithTcpServer("broker.hivemq.com").Build();
var response = await client.ConnectAsync(options, CancellationToken.None);

var output = "NULL";
if (response != null)
{
    output = JsonSerializer.Serialize(response, new JsonSerializerOptions
    {
        WriteIndented = true
    });
}

Console.WriteLine($"[{response?.GetType().Name}]:\r\n{output}");

var disconnectOptions = new MqttClientDisconnectOptions();
await client.DisconnectAsync(disconnectOptions, CancellationToken.None);
MqttClientConnectResult]:
{
  "ResultCode": 0,
  "IsSessionPresent": false,
  "WildcardSubscriptionAvailable": true,
  "RetainAvailable": true,
  "AssignedClientIdentifier": null,
  "AuthenticationMethod": null,
  "AuthenticationData": null,
  "MaximumPacketSize": null,
  "ReasonString": null,
  "ReceiveMaximum": null,
  "MaximumQoS": 0,
  "ResponseInformation": null,
  "TopicAliasMaximum": 0,
  "ServerReference": null,
  "ServerKeepAlive": null,
  "SessionExpiryInterval": null,
  "SubscriptionIdentifiersAvailable": false,
  "SharedSubscriptionAvailable": false,
  "UserProperties": null
}

์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ด์šฉํ•ด ์„œ๋ฒ„ ์—†์ด ์ •์  Blazor WASM์œผ๋กœ ๊ฐ„๋‹จํ•˜๊ฒŒ ์ฑ„ํŒ… ํ”„๋กœ๊ทธ๋žจ ์ƒ˜ํ”Œ์„ ๋งŒ๋“ค์–ด๋ณผ ์˜ˆ์ •์ž…๋‹ˆ๋‹ค.

์ข‹์•„์š” 3