瀏覽代碼

Merge pull request #1055 from chkr1011/add-code-doc

Added client documentation.
release/3.x.x
HansM 3 年之前
committed by GitHub
父節點
當前提交
deb2c3dec6
沒有發現已知的金鑰在資料庫的簽署中 GPG Key ID: 4AEE18F83AFDEB23
共有 43 個文件被更改,包括 773 次插入16 次删除
  1. +8
    -0
      Source/MQTTnet.Extensions.Rpc/Options/TopicGeneration/TopicGenerationContext.cs
  2. +35
    -0
      Source/MQTTnet/Client/Connecting/MqttClientAuthenticateResult.cs
  3. +4
    -0
      Source/MQTTnet/Client/Connecting/MqttClientConnectedEventArgs.cs
  4. +8
    -0
      Source/MQTTnet/Client/Disconnecting/MqttClientDisconnectOptions.cs
  5. +8
    -0
      Source/MQTTnet/Client/Disconnecting/MqttClientDisconnectedEventArgs.cs
  6. +23
    -0
      Source/MQTTnet/Client/ExtendedAuthenticationExchange/MqttExtendedAuthenticationExchangeContext.cs
  7. +21
    -0
      Source/MQTTnet/Client/ExtendedAuthenticationExchange/MqttExtendedAuthenticationExchangeData.cs
  8. +20
    -0
      Source/MQTTnet/Client/IMqttClient.cs
  9. +1
    -2
      Source/MQTTnet/Client/IMqttClientFactory.cs
  10. +78
    -0
      Source/MQTTnet/Client/Options/IMqttClientOptions.cs
  11. +76
    -0
      Source/MQTTnet/Client/Options/MqttClientOptions.cs
  12. +15
    -0
      Source/MQTTnet/Client/Publishing/MqttClientPublishResult.cs
  13. +18
    -0
      Source/MQTTnet/Client/Subscribing/MqttClientSubscribeOptions.cs
  14. +7
    -1
      Source/MQTTnet/Client/Subscribing/MqttClientSubscribeOptionsBuilder.cs
  15. +8
    -0
      Source/MQTTnet/Client/Subscribing/MqttClientSubscribeResultItem.cs
  16. +11
    -0
      Source/MQTTnet/Client/Unsubscribing/MqttClientUnsubscribeOptions.cs
  17. +13
    -0
      Source/MQTTnet/Client/Unsubscribing/MqttClientUnsubscribeOptionsBuilder.cs
  18. +8
    -0
      Source/MQTTnet/Client/Unsubscribing/MqttClientUnsubscribeResultItem.cs
  19. +4
    -0
      Source/MQTTnet/IApplicationMessageReceiver.cs
  20. +71
    -0
      Source/MQTTnet/MqttApplicationMessage.cs
  21. +114
    -8
      Source/MQTTnet/MqttApplicationMessageBuilder.cs
  22. +4
    -0
      Source/MQTTnet/MqttApplicationMessageReceivedEventArgs.cs
  23. +19
    -3
      Source/MQTTnet/MqttTopicFilter.cs
  24. +14
    -0
      Source/MQTTnet/MqttTopicFilterBuilder.cs
  25. +8
    -0
      Source/MQTTnet/Server/CheckSubscriptionsResult.cs
  26. +4
    -0
      Source/MQTTnet/Server/IMqttClientSession.cs
  27. +4
    -0
      Source/MQTTnet/Server/IMqttServerOptions.cs
  28. +12
    -0
      Source/MQTTnet/Server/IMqttServerPersistedSession.cs
  29. +4
    -0
      Source/MQTTnet/Server/MqttApplicationMessageInterceptorContext.cs
  30. +8
    -0
      Source/MQTTnet/Server/MqttClientMessageQueueInterceptorContext.cs
  31. +75
    -1
      Source/MQTTnet/Server/MqttConnectionValidatorContext.cs
  32. +8
    -0
      Source/MQTTnet/Server/MqttQueuedApplicationMessage.cs
  33. +4
    -0
      Source/MQTTnet/Server/MqttServerClientConnectedEventArgs.cs
  34. +5
    -1
      Source/MQTTnet/Server/MqttServerClientDisconnectedEventArgs.cs
  35. +8
    -0
      Source/MQTTnet/Server/MqttServerClientSubscribedTopicEventArgs.cs
  36. +8
    -0
      Source/MQTTnet/Server/MqttServerClientUnsubscribedTopicEventArgs.cs
  37. +4
    -0
      Source/MQTTnet/Server/MqttServerOptions.cs
  38. +8
    -0
      Source/MQTTnet/Server/MqttSubscriptionInterceptorContext.cs
  39. +9
    -0
      Source/MQTTnet/Server/MqttUnsubscriptionInterceptorContext.cs
  40. +4
    -0
      Source/MQTTnet/Server/Status/IMqttClientStatus.cs
  41. +4
    -0
      Source/MQTTnet/Server/Status/IMqttSessionStatus.cs
  42. +4
    -0
      Source/MQTTnet/Server/Status/MqttClientStatus.cs
  43. +4
    -0
      Source/MQTTnet/Server/Status/MqttSessionStatus.cs

+ 8
- 0
Source/MQTTnet.Extensions.Rpc/Options/TopicGeneration/TopicGenerationContext.cs 查看文件

@@ -7,6 +7,14 @@ namespace MQTTnet.Extensions.Rpc.Options.TopicGeneration
{
public string MethodName { get; set; }

/// <summary>
/// Gets or sets the quality of service level.
/// The Quality of Service (QoS) level is an agreement between the sender of a message and the receiver of a message that defines the guarantee of delivery for a specific message.
/// There are 3 QoS levels in MQTT:
/// - At most once (0): Message gets delivered no time, once or multiple times.
/// - At least once (1): Message gets delivered at least once (one time or more often).
/// - Exactly once (2): Message gets delivered exactly once (It's ensured that the message only comes once).
/// </summary>
public MqttQualityOfServiceLevel QualityOfServiceLevel { get; set; }

public IMqttClient MqttClient { get; set; }


+ 35
- 0
Source/MQTTnet/Client/Connecting/MqttClientAuthenticateResult.cs 查看文件

@@ -7,6 +7,10 @@ namespace MQTTnet.Client.Connecting
// TODO: Consider renaming this to _MqttClientConnectResult_
public class MqttClientAuthenticateResult
{
/// <summary>
/// Gets or sets the result code.
/// Hint: MQTT 5 feature only.
/// </summary>
public MqttClientConnectResultCode ResultCode { get; set; }

public bool IsSessionPresent { get; set; }
@@ -17,18 +21,34 @@ namespace MQTTnet.Client.Connecting

public string AssignedClientIdentifier { get; set; }

/// <summary>
/// Gets or sets the authentication method.
/// Hint: MQTT 5 feature only.
/// </summary>
public string AuthenticationMethod { get; set; }

/// <summary>
/// Gets or sets the authentication data.
/// Hint: MQTT 5 feature only.
/// </summary>
public byte[] AuthenticationData { get; set; }

public uint? MaximumPacketSize { get; set; }

/// <summary>
/// Gets or sets the reason string.
/// Hint: MQTT 5 feature only.
/// </summary>
public string ReasonString { get; set; }

public ushort? ReceiveMaximum { get; set; }
public MqttQualityOfServiceLevel MaximumQoS { get; set; }

/// <summary>
/// Gets or sets the response information.
/// Hint: MQTT 5 feature only.
/// </summary>
public string ResponseInformation { get; set; }

public ushort? TopicAliasMaximum { get; set; }
@@ -39,10 +59,25 @@ namespace MQTTnet.Client.Connecting

public uint? SessionExpiryInterval { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the subscription identifiers are available or not.
/// Hint: MQTT 5 feature only.
/// </summary>
public bool? SubscriptionIdentifiersAvailable { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the shared subscriptions are available or not.
/// Hint: MQTT 5 feature only.
/// </summary>
public bool? SharedSubscriptionAvailable { get; set; }

/// <summary>
/// Gets or sets the user properties.
/// In MQTT 5, user properties are basic UTF-8 string key-value pairs that you can append to almost every type of MQTT packet.
/// As long as you don’t exceed the maximum message size, you can use an unlimited number of user properties to add metadata to MQTT messages and pass information between publisher, broker, and subscriber.
/// The feature is very similar to the HTTP header concept.
/// Hint: MQTT 5 feature only.
/// </summary>
public List<MqttUserProperty> UserProperties { get; set; }
}
}

+ 4
- 0
Source/MQTTnet/Client/Connecting/MqttClientConnectedEventArgs.cs 查看文件

@@ -9,6 +9,10 @@ namespace MQTTnet.Client.Connecting
AuthenticateResult = authenticateResult ?? throw new ArgumentNullException(nameof(authenticateResult));
}

/// <summary>
/// Gets the authentication result.
/// Hint: MQTT 5 feature only.
/// </summary>
public MqttClientAuthenticateResult AuthenticateResult { get; }
}
}

+ 8
- 0
Source/MQTTnet/Client/Disconnecting/MqttClientDisconnectOptions.cs 查看文件

@@ -2,8 +2,16 @@
{
public sealed class MqttClientDisconnectOptions
{
/// <summary>
/// Gets or sets the reason code.
/// Hint: MQTT 5 feature only.
/// </summary>
public MqttClientDisconnectReason ReasonCode { get; set; } = MqttClientDisconnectReason.NormalDisconnection;

/// <summary>
/// Gets or sets the reason string.
/// Hint: MQTT 5 feature only.
/// </summary>
public string ReasonString { get; set; }
}
}

+ 8
- 0
Source/MQTTnet/Client/Disconnecting/MqttClientDisconnectedEventArgs.cs 查看文件

@@ -19,8 +19,16 @@ namespace MQTTnet.Client.Disconnecting

public Exception Exception { get; }

/// <summary>
/// Gets the authentication result.
/// Hint: MQTT 5 feature only.
/// </summary>
public MqttClientAuthenticateResult AuthenticateResult { get; }

/// <summary>
/// Gets or sets the reason.
/// Hint: MQTT 5 feature only.
/// </summary>
public MqttClientDisconnectReason Reason { get; set; }

[Obsolete("Please use 'Reason' instead. This property will be removed in the future!")]


+ 23
- 0
Source/MQTTnet/Client/ExtendedAuthenticationExchange/MqttExtendedAuthenticationExchangeContext.cs 查看文件

@@ -20,14 +20,37 @@ namespace MQTTnet.Client.ExtendedAuthenticationExchange
Client = client ?? throw new ArgumentNullException(nameof(client));
}

/// <summary>
/// Gets the reason code.
/// Hint: MQTT 5 feature only.
/// </summary>
public MqttAuthenticateReasonCode ReasonCode { get; }

/// <summary>
/// Gets the reason string.
/// Hint: MQTT 5 feature only.
/// </summary>
public string ReasonString { get; }

/// <summary>
/// Gets the authentication method.
/// Hint: MQTT 5 feature only.
/// </summary>
public string AuthenticationMethod { get; }

/// <summary>
/// Gets the authentication data.
/// Hint: MQTT 5 feature only.
/// </summary>
public byte[] AuthenticationData { get; }

/// <summary>
/// Gets the user properties.
/// In MQTT 5, user properties are basic UTF-8 string key-value pairs that you can append to almost every type of MQTT packet.
/// As long as you don’t exceed the maximum message size, you can use an unlimited number of user properties to add metadata to MQTT messages and pass information between publisher, broker, and subscriber.
/// The feature is very similar to the HTTP header concept.
/// Hint: MQTT 5 feature only.
/// </summary>
public List<MqttUserProperty> UserProperties { get; }

public IMqttClient Client { get; }


+ 21
- 0
Source/MQTTnet/Client/ExtendedAuthenticationExchange/MqttExtendedAuthenticationExchangeData.cs 查看文件

@@ -6,12 +6,33 @@ namespace MQTTnet.Client.ExtendedAuthenticationExchange
{
public class MqttExtendedAuthenticationExchangeData
{
/// <summary>
/// Gets or sets the reason code.
/// Hint: MQTT 5 feature only.
/// </summary>
public MqttAuthenticateReasonCode ReasonCode { get; set; }

/// <summary>
/// Gets or sets the reason string.
/// Hint: MQTT 5 feature only.
/// </summary>
public string ReasonString { get; set; }

/// <summary>
/// Gets or sets the authentication data.
/// Authentication data is binary information used to transmit multiple iterations of cryptographic secrets of protocol steps.
/// The content of the authentication data is highly dependent on the specific implementation of the authentication method.
/// Hint: MQTT 5 feature only.
/// </summary>
public byte[] AuthenticationData { get; set; }

/// <summary>
/// Gets or sets the user properties.
/// In MQTT 5, user properties are basic UTF-8 string key-value pairs that you can append to almost every type of MQTT packet.
/// As long as you don’t exceed the maximum message size, you can use an unlimited number of user properties to add metadata to MQTT messages and pass information between publisher, broker, and subscriber.
/// The feature is very similar to the HTTP header concept.
/// Hint: MQTT 5 feature only.
/// </summary>
public List<MqttUserProperty> UserProperties { get; }
}
}

+ 20
- 0
Source/MQTTnet/Client/IMqttClient.cs 查看文件

@@ -13,18 +13,38 @@ namespace MQTTnet.Client
public interface IMqttClient : IApplicationMessageReceiver, IApplicationMessagePublisher, IDisposable
{
bool IsConnected { get; }

IMqttClientOptions Options { get; }

/// <summary>
/// Gets or sets the connected handler that is fired after the client has connected to the server successfully.
/// Hint: Initialize handlers before you connect the client to avoid issues.
/// </summary>
IMqttClientConnectedHandler ConnectedHandler { get; set; }

/// <summary>
/// Gets or sets the disconnected handler that is fired after the client has disconnected from the server.
/// Hint: Initialize handlers before you connect the client to avoid issues.
/// </summary>
IMqttClientDisconnectedHandler DisconnectedHandler { get; set; }

Task<MqttClientAuthenticateResult> ConnectAsync(IMqttClientOptions options, CancellationToken cancellationToken);

Task DisconnectAsync(MqttClientDisconnectOptions options, CancellationToken cancellationToken);

Task PingAsync(CancellationToken cancellationToken);

/// <summary>
/// Sends extended authentication data.
/// Hint: MQTT 5 feature only.
/// </summary>
/// <param name="data">The extended data.</param>
/// <param name="cancellationToken">A cancellation token to stop the task.</param>
/// <returns>A <see cref="Task"/> representing any asynchronous operation.</returns>
Task SendExtendedAuthenticationExchangeDataAsync(MqttExtendedAuthenticationExchangeData data, CancellationToken cancellationToken);

Task<MqttClientSubscribeResult> SubscribeAsync(MqttClientSubscribeOptions options, CancellationToken cancellationToken);

Task<MqttClientUnsubscribeResult> UnsubscribeAsync(MqttClientUnsubscribeOptions options, CancellationToken cancellationToken);
}
}

+ 1
- 2
Source/MQTTnet/Client/IMqttClientFactory.cs 查看文件

@@ -1,5 +1,4 @@
using System;
using MQTTnet.Adapter;
using MQTTnet.Adapter;
using MQTTnet.Diagnostics;
using MQTTnet.LowLevelClient;



+ 78
- 0
Source/MQTTnet/Client/Options/IMqttClientOptions.cs 查看文件

@@ -9,26 +9,104 @@ namespace MQTTnet.Client.Options
{
public interface IMqttClientOptions
{
/// <summary>
/// Gets the client identifier.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
/// </summary>
string ClientId { get; }

/// <summary>
/// Gets a value indicating whether clean sessions are used or not.
/// When a client connects to a broker it can connect using either a non persistent connection (clean session) or a persistent connection.
/// With a non persistent connection the broker doesn't store any subscription information or undelivered messages for the client.
/// This mode is ideal when the client only publishes messages.
/// It can also connect as a durable client using a persistent connection.
/// In this mode, the broker will store subscription information, and undelivered messages for the client.
/// </summary>
bool CleanSession { get; }

IMqttClientCredentials Credentials { get; }

IMqttExtendedAuthenticationExchangeHandler ExtendedAuthenticationExchangeHandler { get; }

MqttProtocolVersion ProtocolVersion { get; }

IMqttClientChannelOptions ChannelOptions { get; }

TimeSpan CommunicationTimeout { get; }

/// <summary>
/// Gets the keep alive period.
/// The connection is normally left open by the client so that is can send and receive data at any time.
/// If no data flows over an open connection for a certain time period then the client will generate a PINGREQ and expect to receive a PINGRESP from the broker.
/// This message exchange confirms that the connection is open and working.
/// This period is known as the keep alive period.
/// </summary>
TimeSpan KeepAlivePeriod { get; }

/// <summary>
/// Gets the last will message.
/// In MQTT, you use the last will message feature to notify other clients about an ungracefully disconnected client.
/// </summary>
MqttApplicationMessage WillMessage { get; }

/// <summary>
/// Gets the will delay interval.
/// This is the time between the client disconnect and the time the will message will be sent.
/// </summary>
uint? WillDelayInterval { get; }

/// <summary>
/// Gets the authentication method.
/// Hint: MQTT 5 feature only.
/// </summary>
string AuthenticationMethod { get; }

/// <summary>
/// Gets the authentication data.
/// Hint: MQTT 5 feature only.
/// </summary>
byte[] AuthenticationData { get; }

uint? MaximumPacketSize { get; }

/// <summary>
/// Gets the receive maximum.
/// This gives the maximum length of the receive messages.
/// </summary>
ushort? ReceiveMaximum { get; }

/// <summary>
/// Gets the request problem information.
/// Hint: MQTT 5 feature only.
/// </summary>
bool? RequestProblemInformation { get; }

/// <summary>
/// Gets the request response information.
/// Hint: MQTT 5 feature only.
/// </summary>
bool? RequestResponseInformation { get; }

/// <summary>
/// Gets the session expiry interval.
/// The time after a session expires when it's not actively used.
/// </summary>
uint? SessionExpiryInterval { get; }

/// <summary>
/// Gets the topic alias maximum.
/// This gives the maximum length of the topic alias.
/// </summary>
ushort? TopicAliasMaximum { get; }

/// <summary>
/// Gets or sets the user properties.
/// In MQTT 5, user properties are basic UTF-8 string key-value pairs that you can append to almost every type of MQTT packet.
/// As long as you don’t exceed the maximum message size, you can use an unlimited number of user properties to add metadata to MQTT messages and pass information between publisher, broker, and subscriber.
/// The feature is very similar to the HTTP header concept.
/// Hint: MQTT 5 feature only.
/// </summary>
List<MqttUserProperty> UserProperties { get; set; }

IMqttPacketInspector PacketInspector { get; set; }


+ 76
- 0
Source/MQTTnet/Client/Options/MqttClientOptions.cs 查看文件

@@ -9,28 +9,104 @@ namespace MQTTnet.Client.Options
{
public class MqttClientOptions : IMqttClientOptions
{
/// <summary>
/// Gets the client identifier.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
/// </summary>
public string ClientId { get; set; } = Guid.NewGuid().ToString("N");

/// <summary>
/// Gets or sets a value indicating whether clean sessions are used or not.
/// When a client connects to a broker it can connect using either a non persistent connection (clean session) or a persistent connection.
/// With a non persistent connection the broker doesn't store any subscription information or undelivered messages for the client.
/// This mode is ideal when the client only publishes messages.
/// It can also connect as a durable client using a persistent connection.
/// In this mode, the broker will store subscription information, and undelivered messages for the client.
/// </summary>
public bool CleanSession { get; set; } = true;

public IMqttClientCredentials Credentials { get; set; }

public IMqttExtendedAuthenticationExchangeHandler ExtendedAuthenticationExchangeHandler { get; set; }

public MqttProtocolVersion ProtocolVersion { get; set; } = MqttProtocolVersion.V311;

public IMqttClientChannelOptions ChannelOptions { get; set; }

public TimeSpan CommunicationTimeout { get; set; } = TimeSpan.FromSeconds(10);

/// <summary>
/// Gets or sets the keep alive period.
/// The connection is normally left open by the client so that is can send and receive data at any time.
/// If no data flows over an open connection for a certain time period then the client will generate a PINGREQ and expect to receive a PINGRESP from the broker.
/// This message exchange confirms that the connection is open and working.
/// This period is known as the keep alive period.
/// </summary>
public TimeSpan KeepAlivePeriod { get; set; } = TimeSpan.FromSeconds(15);

/// <summary>
/// Gets or sets the last will message.
/// In MQTT, you use the last will message feature to notify other clients about an ungracefully disconnected client.
/// </summary>
public MqttApplicationMessage WillMessage { get; set; }

/// <summary>
/// Gets or sets the will delay interval.
/// This is the time between the client disconnect and the time the will message will be sent.
/// </summary>
public uint? WillDelayInterval { get; set; }

/// <summary>
/// Gets or sets the authentication method.
/// Hint: MQTT 5 feature only.
/// </summary>
public string AuthenticationMethod { get; set; }

/// <summary>
/// Gets or sets the authentication data.
/// Hint: MQTT 5 feature only.
/// </summary>
public byte[] AuthenticationData { get; set; }

public uint? MaximumPacketSize { get; set; }

/// <summary>
/// Gets or sets the receive maximum.
/// This gives the maximum length of the receive messages.
/// </summary>
public ushort? ReceiveMaximum { get; set; }

/// <summary>
/// Gets or sets the request problem information.
/// Hint: MQTT 5 feature only.
/// </summary>
public bool? RequestProblemInformation { get; set; }

/// <summary>
/// Gets or sets the request response information.
/// Hint: MQTT 5 feature only.
/// </summary>
public bool? RequestResponseInformation { get; set; }

/// <summary>
/// Gets or sets the session expiry interval.
/// The time after a session expires when it's not actively used.
/// </summary>
public uint? SessionExpiryInterval { get; set; }

/// <summary>
/// Gets or sets the topic alias maximum.
/// This gives the maximum length of the topic alias.
/// </summary>
public ushort? TopicAliasMaximum { get; set; }

/// <summary>
/// Gets or sets the user properties.
/// In MQTT 5, user properties are basic UTF-8 string key-value pairs that you can append to almost every type of MQTT packet.
/// As long as you don’t exceed the maximum message size, you can use an unlimited number of user properties to add metadata to MQTT messages and pass information between publisher, broker, and subscriber.
/// The feature is very similar to the HTTP header concept.
/// Hint: MQTT 5 feature only.
/// </summary>
public List<MqttUserProperty> UserProperties { get; set; }

public IMqttPacketInspector PacketInspector { get; set; }


+ 15
- 0
Source/MQTTnet/Client/Publishing/MqttClientPublishResult.cs 查看文件

@@ -8,10 +8,25 @@ namespace MQTTnet.Client.Publishing
{
public ushort? PacketIdentifier { get; set; }

/// <summary>
/// Gets or sets the reason code.
/// Hint: MQTT 5 feature only.
/// </summary>
public MqttClientPublishReasonCode ReasonCode { get; set; } = MqttClientPublishReasonCode.Success;

/// <summary>
/// Gets or sets the reason string.
/// Hint: MQTT 5 feature only.
/// </summary>
public string ReasonString { get; set; }

/// <summary>
/// Gets or sets the user properties.
/// In MQTT 5, user properties are basic UTF-8 string key-value pairs that you can append to almost every type of MQTT packet.
/// As long as you don’t exceed the maximum message size, you can use an unlimited number of user properties to add metadata to MQTT messages and pass information between publisher, broker, and subscriber.
/// The feature is very similar to the HTTP header concept.
/// Hint: MQTT 5 feature only.
/// </summary>
public List<MqttUserProperty> UserProperties { get; set; }
}
}

+ 18
- 0
Source/MQTTnet/Client/Subscribing/MqttClientSubscribeOptions.cs 查看文件

@@ -5,10 +5,28 @@ namespace MQTTnet.Client.Subscribing
{
public class MqttClientSubscribeOptions
{
/// <summary>
/// Gets or sets a list of topic filters the client wants to subscribe to.
/// Topic filters can include regular topics or wild cards.
/// </summary>
public List<MqttTopicFilter> TopicFilters { get; set; } = new List<MqttTopicFilter>();

/// <summary>
/// Gets or sets the subscription identifier.
/// The client can specify a subscription identifier when subscribing.
/// The broker will establish and store the mapping relationship between this subscription and subscription identifier when successfully create or modify subscription.
/// The broker will return the subscription identifier associated with this PUBLISH packet and the PUBLISH packet to the client when need to forward PUBLISH packets matching this subscription to this client.
/// Hint: MQTT 5 feature only.
/// </summary>
public uint? SubscriptionIdentifier { get; set; }

/// <summary>
/// Gets or sets the user properties.
/// In MQTT 5, user properties are basic UTF-8 string key-value pairs that you can append to almost every type of MQTT packet.
/// As long as you don’t exceed the maximum message size, you can use an unlimited number of user properties to add metadata to MQTT messages and pass information between publisher, broker, and subscriber.
/// The feature is very similar to the HTTP header concept.
/// Hint: MQTT 5 feature only.
/// </summary>
public List<MqttUserProperty> UserProperties { get; set; }
}
}

+ 7
- 1
Source/MQTTnet/Client/Subscribing/MqttClientSubscribeOptionsBuilder.cs 查看文件

@@ -9,6 +9,13 @@ namespace MQTTnet.Client.Subscribing
{
private readonly MqttClientSubscribeOptions _subscribeOptions = new MqttClientSubscribeOptions();

/// <summary>
/// Adds the user property to the subscribe options.
/// Hint: MQTT 5 feature only.
/// </summary>
/// <param name="name">The property name.</param>
/// <param name="value">The property value.</param>
/// <returns>A new instance of the <see cref="MqttApplicationMessageBuilder"/> class.</returns>
public MqttClientSubscribeOptionsBuilder WithUserProperty(string name, string value)
{
if (name == null) throw new ArgumentNullException(nameof(name));
@@ -27,7 +34,6 @@ namespace MQTTnet.Client.Subscribing
public MqttClientSubscribeOptionsBuilder WithSubscriptionIdentifier(uint? subscriptionIdentifier)
{
_subscribeOptions.SubscriptionIdentifier = subscriptionIdentifier;

return this;
}



+ 8
- 0
Source/MQTTnet/Client/Subscribing/MqttClientSubscribeResultItem.cs 查看文件

@@ -10,8 +10,16 @@ namespace MQTTnet.Client.Subscribing
ResultCode = resultCode;
}

/// <summary>
/// Gets or sets the topic filter.
/// The topic filter can contain topics and wildcards.
/// </summary>
public MqttTopicFilter TopicFilter { get; }

/// <summary>
/// Gets or sets the result code.
/// Hint: MQTT 5 feature only.
/// </summary>
public MqttClientSubscribeResultCode ResultCode { get; }
}
}

+ 11
- 0
Source/MQTTnet/Client/Unsubscribing/MqttClientUnsubscribeOptions.cs 查看文件

@@ -5,8 +5,19 @@ namespace MQTTnet.Client.Unsubscribing
{
public class MqttClientUnsubscribeOptions
{
/// <summary>
/// Gets or sets a list of topic filters the client wants to unsubscribe from.
/// Topic filters can include regular topics or wild cards.
/// </summary>
public List<string> TopicFilters { get; set; } = new List<string>();

/// <summary>
/// Gets or sets the user properties.
/// In MQTT 5, user properties are basic UTF-8 string key-value pairs that you can append to almost every type of MQTT packet.
/// As long as you don’t exceed the maximum message size, you can use an unlimited number of user properties to add metadata to MQTT messages and pass information between publisher, broker, and subscriber.
/// The feature is very similar to the HTTP header concept.
/// Hint: MQTT 5 feature only.
/// </summary>
public List<MqttUserProperty> UserProperties { get; set; } = new List<MqttUserProperty>();
}
}

+ 13
- 0
Source/MQTTnet/Client/Unsubscribing/MqttClientUnsubscribeOptionsBuilder.cs 查看文件

@@ -8,6 +8,13 @@ namespace MQTTnet.Client.Unsubscribing
{
private readonly MqttClientUnsubscribeOptions _unsubscribeOptions = new MqttClientUnsubscribeOptions();

/// <summary>
/// Adds the user property to the unsubscribe options.
/// Hint: MQTT 5 feature only.
/// </summary>
/// <param name="name">The property name.</param>
/// <param name="value">The property value.</param>
/// <returns>A new instance of the <see cref="MqttClientUnsubscribeOptionsBuilder"/> class.</returns>
public MqttClientUnsubscribeOptionsBuilder WithUserProperty(string name, string value)
{
if (name is null) throw new ArgumentNullException(nameof(name));
@@ -16,6 +23,12 @@ namespace MQTTnet.Client.Unsubscribing
return WithUserProperty(new MqttUserProperty(name, value));
}

/// <summary>
/// Adds the user property to the unsubscribe options.
/// Hint: MQTT 5 feature only.
/// </summary>
/// <param name="userProperty">The user property.</param>
/// <returns>A new instance of the <see cref="MqttClientUnsubscribeOptionsBuilder"/> class.</returns>
public MqttClientUnsubscribeOptionsBuilder WithUserProperty(MqttUserProperty userProperty)
{
if (userProperty is null) throw new ArgumentNullException(nameof(userProperty));


+ 8
- 0
Source/MQTTnet/Client/Unsubscribing/MqttClientUnsubscribeResultItem.cs 查看文件

@@ -10,8 +10,16 @@ namespace MQTTnet.Client.Unsubscribing
ReasonCode = reasonCode;
}

/// <summary>
/// Gets or sets the topic filter.
/// The topic filter can contain topics and wildcards.
/// </summary>
public string TopicFilter { get; }

/// <summary>
/// Gets or sets the result code.
/// Hint: MQTT 5 feature only.
/// </summary>
public MqttClientUnsubscribeResultCode ReasonCode { get; }
}
}

+ 4
- 0
Source/MQTTnet/IApplicationMessageReceiver.cs 查看文件

@@ -4,6 +4,10 @@ namespace MQTTnet
{
public interface IApplicationMessageReceiver
{
/// <summary>
/// Gets or sets the application message received handler that is fired every time a new message is received on the client's subscriptions.
/// Hint: Initialize handlers before you connect the client to avoid issues.
/// </summary>
IMqttApplicationMessageReceivedHandler ApplicationMessageReceivedHandler { get; set; }
}
}

+ 71
- 0
Source/MQTTnet/MqttApplicationMessage.cs 查看文件

@@ -6,28 +6,99 @@ namespace MQTTnet
{
public class MqttApplicationMessage
{
/// <summary>
/// Gets or sets the MQTT topic.
/// In MQTT, the word topic refers to an UTF-8 string that the broker uses to filter messages for each connected client.
/// The topic consists of one or more topic levels. Each topic level is separated by a forward slash (topic level separator).
/// </summary>
public string Topic { get; set; }

/// <summary>
/// Gets or sets the payload.
/// The payload is the data bytes sent via the MQTT protocol.
/// </summary>
public byte[] Payload { get; set; }

/// <summary>
/// Gets or sets the quality of service level.
/// The Quality of Service (QoS) level is an agreement between the sender of a message and the receiver of a message that defines the guarantee of delivery for a specific message.
/// There are 3 QoS levels in MQTT:
/// - At most once (0): Message gets delivered no time, once or multiple times.
/// - At least once (1): Message gets delivered at least once (one time or more often).
/// - Exactly once (2): Message gets delivered exactly once (It's ensured that the message only comes once).
/// </summary>
public MqttQualityOfServiceLevel QualityOfServiceLevel { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the message should be retained or not.
/// A retained message is a normal MQTT message with the retained flag set to true.
/// The broker stores the last retained message and the corresponding QoS for that topic.
/// </summary>
public bool Retain { get; set; }

/// <summary>
/// Gets or sets the user properties.
/// In MQTT 5, user properties are basic UTF-8 string key-value pairs that you can append to almost every type of MQTT packet.
/// As long as you don’t exceed the maximum message size, you can use an unlimited number of user properties to add metadata to MQTT messages and pass information between publisher, broker, and subscriber.
/// The feature is very similar to the HTTP header concept.
/// Hint: MQTT 5 feature only.
/// </summary>
public List<MqttUserProperty> UserProperties { get; set; }

/// <summary>
/// Gets or sets the content type.
/// The content type must be a UTF-8 encoded string. The content type value identifies the kind of UTF-8 encoded payload.
/// </summary>
public string ContentType { get; set; }

/// <summary>
/// Gets or sets the response topic.
/// In MQTT 5 the ability to publish a response topic was added in the publish message which allows you to implement the request/response pattern between clients that is common in web applications.
/// Hint: MQTT 5 feature only.
/// </summary>
public string ResponseTopic { get; set; }

/// <summary>
/// Gets or sets the payload format indicator.
/// The payload format indicator is part of any MQTT packet that can contain a payload. The indicator is an optional byte value.
/// A value of 0 indicates an “unspecified byte stream”.
/// A value of 1 indicates a "UTF-8 encoded payload".
/// If no payload format indicator is provided, the default value is 0.
/// Hint: MQTT 5 feature only.
/// </summary>
public MqttPayloadFormatIndicator? PayloadFormatIndicator { get; set; }

/// <summary>
/// Gets or sets the message expiry interval.
/// A client can set the message expiry interval in seconds for each PUBLISH message individually.
/// This interval defines the period of time that the broker stores the PUBLISH message for any matching subscribers that are not currently connected.
/// When no message expiry interval is set, the broker must store the message for matching subscribers indefinitely.
/// When the retained=true option is set on the PUBLISH message, this interval also defines how long a message is retained on a topic.
/// Hint: MQTT 5 feature only.
/// </summary>
public uint? MessageExpiryInterval { get; set; }

/// <summary>
/// Gets or sets the topic alias.
/// Topic aliases were introduced are a mechanism for reducing the size of published packets by reducing the size of the topic field.
/// Hint: MQTT 5 feature only.
/// </summary>
public ushort? TopicAlias { get; set; }

/// <summary>
/// Gets or sets the correlation data.
/// In order for the sender to know what sent message the response refers to it can also send correlation data with the published message.
/// Hint: MQTT 5 feature only.
/// </summary>
public byte[] CorrelationData { get; set; }

/// <summary>
/// Gets or sets the subscription identifiers.
/// The client can specify a subscription identifier when subscribing.
/// The broker will establish and store the mapping relationship between this subscription and subscription identifier when successfully create or modify subscription.
/// The broker will return the subscription identifier associated with this PUBLISH packet and the PUBLISH packet to the client when need to forward PUBLISH packets matching this subscription to this client.
/// Hint: MQTT 5 feature only.
/// </summary>
public List<uint> SubscriptionIdentifiers { get; set; }
}
}

+ 114
- 8
Source/MQTTnet/MqttApplicationMessageBuilder.cs 查看文件

@@ -11,17 +11,99 @@ namespace MQTTnet
{
public class MqttApplicationMessageBuilder
{
/// <summary>
/// The quality of service level.
/// The Quality of Service (QoS) level is an agreement between the sender of a message and the receiver of a message that defines the guarantee of delivery for a specific message.
/// There are 3 QoS levels in MQTT:
/// - At most once (0): Message gets delivered no time, once or multiple times.
/// - At least once (1): Message gets delivered at least once (one time or more often).
/// - Exactly once (2): Message gets delivered exactly once (It's ensured that the message only comes once).
/// </summary>
private MqttQualityOfServiceLevel _qualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce;

/// <summary>
/// The MQTT topic.
/// In MQTT, the word topic refers to an UTF-8 string that the broker uses to filter messages for each connected client.
/// The topic consists of one or more topic levels. Each topic level is separated by a forward slash (topic level separator).
/// </summary>
private string _topic;

/// <summary>
/// The payload.
/// The payload is the data bytes sent via the MQTT protocol.
/// </summary>
private byte[] _payload;

/// <summary>
/// A value indicating whether the message should be retained or not.
/// A retained message is a normal MQTT message with the retained flag set to true.
/// The broker stores the last retained message and the corresponding QoS for that topic.
/// </summary>
private bool _retain;

/// <summary>
/// The content type.
/// The content type must be a UTF-8 encoded string. The content type value identifies the kind of UTF-8 encoded payload.
/// </summary>
private string _contentType;

/// <summary>
/// The response topic.
/// In MQTT 5 the ability to publish a response topic was added in the publish message which allows you to implement the request/response pattern between clients that is common in web applications.
/// Hint: MQTT 5 feature only.
/// </summary>
private string _responseTopic;

/// <summary>
/// The correlation data.
/// In order for the sender to know what sent message the response refers to it can also send correlation data with the published message.
/// Hint: MQTT 5 feature only.
/// </summary>
private byte[] _correlationData;

/// <summary>
/// The topic alias.
/// Topic aliases were introduced are a mechanism for reducing the size of published packets by reducing the size of the topic field.
/// Hint: MQTT 5 feature only.
/// </summary>
private ushort? _topicAlias;

/// <summary>
/// The subscription identifiers.
/// The client can specify a subscription identifier when subscribing.
/// The broker will establish and store the mapping relationship between this subscription and subscription identifier when successfully create or modify subscription.
/// The broker will return the subscription identifier associated with this PUBLISH packet and the PUBLISH packet to the client when need to forward PUBLISH packets matching this subscription to this client.
/// Hint: MQTT 5 feature only.
/// </summary>
private List<uint> _subscriptionIdentifiers;

/// <summary>
/// The message expiry interval.
/// A client can set the message expiry interval in seconds for each PUBLISH message individually.
/// This interval defines the period of time that the broker stores the PUBLISH message for any matching subscribers that are not currently connected.
/// When no message expiry interval is set, the broker must store the message for matching subscribers indefinitely.
/// When the retained=true option is set on the PUBLISH message, this interval also defines how long a message is retained on a topic.
/// Hint: MQTT 5 feature only.
/// </summary>
private uint? _messageExpiryInterval;

/// <summary>
/// The payload format indicator.
/// The payload format indicator is part of any MQTT packet that can contain a payload. The indicator is an optional byte value.
/// A value of 0 indicates an “unspecified byte stream”.
/// A value of 1 indicates a "UTF-8 encoded payload".
/// If no payload format indicator is provided, the default value is 0.
/// Hint: MQTT 5 feature only.
/// </summary>
private MqttPayloadFormatIndicator? _payloadFormatIndicator;

/// <summary>
/// The user properties.
/// In MQTT 5, user properties are basic UTF-8 string key-value pairs that you can append to almost every type of MQTT packet.
/// As long as you don’t exceed the maximum message size, you can use an unlimited number of user properties to add metadata to MQTT messages and pass information between publisher, broker, and subscriber.
/// The feature is very similar to the HTTP header concept.
/// </summary>
/// Hint: MQTT 5 feature only.
private List<MqttUserProperty> _userProperties;

public MqttApplicationMessageBuilder WithTopic(string topic)
@@ -139,8 +221,12 @@ namespace MQTTnet
}

/// <summary>
/// This is only supported when using MQTTv5.
/// Adds the user property to the message.
/// Hint: MQTT 5 feature only.
/// </summary>
/// <param name="name">The property name.</param>
/// <param name="value">The property value.</param>
/// <returns>A new instance of the <see cref="MqttApplicationMessageBuilder"/> class.</returns>
public MqttApplicationMessageBuilder WithUserProperty(string name, string value)
{
if (_userProperties == null)
@@ -153,8 +239,10 @@ namespace MQTTnet
}

/// <summary>
/// This is only supported when using MQTTv5.
/// Adds the content type to the message.
/// Hint: MQTT 5 feature only.
/// </summary>
/// <returns>A new instance of the <see cref="MqttApplicationMessageBuilder"/> class.</returns>
public MqttApplicationMessageBuilder WithContentType(string contentType)
{
_contentType = contentType;
@@ -162,8 +250,11 @@ namespace MQTTnet
}

/// <summary>
/// This is only supported when using MQTTv5.
/// Adds the response topic to the message.
/// Hint: MQTT 5 feature only.
/// </summary>
/// <param name="responseTopic">The response topic.</param>
/// <returns>A new instance of the <see cref="MqttApplicationMessageBuilder"/> class.</returns>
public MqttApplicationMessageBuilder WithResponseTopic(string responseTopic)
{
_responseTopic = responseTopic;
@@ -171,8 +262,11 @@ namespace MQTTnet
}

/// <summary>
/// This is only supported when using MQTTv5.
/// Adds the correlation data to the message.
/// Hint: MQTT 5 feature only.
/// </summary>
/// <param name="correlationData">The correlation data.</param>
/// <returns>A new instance of the <see cref="MqttApplicationMessageBuilder"/> class.</returns>
public MqttApplicationMessageBuilder WithCorrelationData(byte[] correlationData)
{
_correlationData = correlationData;
@@ -180,8 +274,11 @@ namespace MQTTnet
}

/// <summary>
/// This is only supported when using MQTTv5.
/// Adds the topic alias to the message.
/// Hint: MQTT 5 feature only.
/// </summary>
/// <param name="topicAlias">The topic alias.</param>
/// <returns>A new instance of the <see cref="MqttApplicationMessageBuilder"/> class.</returns>
public MqttApplicationMessageBuilder WithTopicAlias(ushort topicAlias)
{
_topicAlias = topicAlias;
@@ -189,8 +286,11 @@ namespace MQTTnet
}

/// <summary>
/// This is only supported when using MQTTv5.
/// Adds the subscription identifier to the message.
/// Hint: MQTT 5 feature only.
/// </summary>
/// <param name="subscriptionIdentifier">The subscription identifier.</param>
/// <returns>A new instance of the <see cref="MqttApplicationMessageBuilder"/> class.</returns>
public MqttApplicationMessageBuilder WithSubscriptionIdentifier(uint subscriptionIdentifier)
{
if (_subscriptionIdentifiers == null)
@@ -203,8 +303,11 @@ namespace MQTTnet
}

/// <summary>
/// This is only supported when using MQTTv5.
/// Adds the message expiry interval to the message.
/// Hint: MQTT 5 feature only.
/// </summary>
/// <param name="messageExpiryInterval">The message expiry interval.</param>
/// <returns>A new instance of the <see cref="MqttApplicationMessageBuilder"/> class.</returns>
public MqttApplicationMessageBuilder WithMessageExpiryInterval(uint messageExpiryInterval)
{
_messageExpiryInterval = messageExpiryInterval;
@@ -212,8 +315,11 @@ namespace MQTTnet
}

/// <summary>
/// This is only supported when using MQTTv5.
/// Adds the payload format indicator to the message.
/// Hint: MQTT 5 feature only.
/// </summary>
/// <param name="payloadFormatIndicator">The payload format indicator.</param>
/// <returns>A new instance of the <see cref="MqttApplicationMessageBuilder"/> class.</returns>
public MqttApplicationMessageBuilder WithPayloadFormatIndicator(MqttPayloadFormatIndicator payloadFormatIndicator)
{
_payloadFormatIndicator = payloadFormatIndicator;


+ 4
- 0
Source/MQTTnet/MqttApplicationMessageReceivedEventArgs.cs 查看文件

@@ -10,6 +10,10 @@ namespace MQTTnet
ApplicationMessage = applicationMessage ?? throw new ArgumentNullException(nameof(applicationMessage));
}

/// <summary>
/// Gets the client identifier.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
/// </summary>
public string ClientId { get; }

public MqttApplicationMessage ApplicationMessage { get; }


+ 19
- 3
Source/MQTTnet/MqttTopicFilter.cs 查看文件

@@ -10,22 +10,38 @@ namespace MQTTnet

public class MqttTopicFilter
{
/// <summary>
/// Gets or sets the MQTT topic.
/// In MQTT, the word topic refers to an UTF-8 string that the broker uses to filter messages for each connected client.
/// The topic consists of one or more topic levels. Each topic level is separated by a forward slash (topic level separator).
/// </summary>
public string Topic { get; set; }

/// <summary>
/// Gets or sets the quality of service level.
/// The Quality of Service (QoS) level is an agreement between the sender of a message and the receiver of a message that defines the guarantee of delivery for a specific message.
/// There are 3 QoS levels in MQTT:
/// - At most once (0): Message gets delivered no time, once or multiple times.
/// - At least once (1): Message gets delivered at least once (one time or more often).
/// - Exactly once (2): Message gets delivered exactly once (It's ensured that the message only comes once).
/// </summary>
public MqttQualityOfServiceLevel QualityOfServiceLevel { get; set; }

/// <summary>
/// This is only supported when using MQTTv5.
/// Gets or sets a value indicating whether to not send messages originating on this client (noLocal) or not.
/// </summary>
/// Hint: MQTT 5 feature only.
public bool? NoLocal { get; set; }

/// <summary>
/// This is only supported when using MQTTv5.
/// Gets or sets a value indicating whether messages are retained as published or not.
/// Hint: MQTT 5 feature only.
/// </summary>
public bool? RetainAsPublished { get; set; }

/// <summary>
/// This is only supported when using MQTTv5.
/// Gets or sets the retain handling.
/// Hint: MQTT 5 feature only.
/// </summary>
public MqttRetainHandling? RetainHandling { get; set; }



+ 14
- 0
Source/MQTTnet/MqttTopicFilterBuilder.cs 查看文件

@@ -11,7 +11,21 @@ namespace MQTTnet

public class MqttTopicFilterBuilder
{
/// <summary>
/// The quality of service level.
/// The Quality of Service (QoS) level is an agreement between the sender of a message and the receiver of a message that defines the guarantee of delivery for a specific message.
/// There are 3 QoS levels in MQTT:
/// - At most once (0): Message gets delivered no time, once or multiple times.
/// - At least once (1): Message gets delivered at least once (one time or more often).
/// - Exactly once (2): Message gets delivered exactly once (It's ensured that the message only comes once).
/// </summary>
MqttQualityOfServiceLevel _qualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce;

/// <summary>
/// The MQTT topic.
/// In MQTT, the word topic refers to an UTF-8 string that the broker uses to filter messages for each connected client.
/// The topic consists of one or more topic levels. Each topic level is separated by a forward slash (topic level separator).
/// </summary>
string _topic;
bool? _noLocal;
bool? _retainAsPublished;


+ 8
- 0
Source/MQTTnet/Server/CheckSubscriptionsResult.cs 查看文件

@@ -8,6 +8,14 @@ namespace MQTTnet.Server

public bool IsSubscribed { get; set; }

/// <summary>
/// Gets or sets the quality of service level.
/// The Quality of Service (QoS) level is an agreement between the sender of a message and the receiver of a message that defines the guarantee of delivery for a specific message.
/// There are 3 QoS levels in MQTT:
/// - At most once (0): Message gets delivered no time, once or multiple times.
/// - At least once (1): Message gets delivered at least once (one time or more often).
/// - Exactly once (2): Message gets delivered exactly once (It's ensured that the message only comes once).
/// </summary>
public MqttQualityOfServiceLevel QualityOfServiceLevel { get; set; }
}
}

+ 4
- 0
Source/MQTTnet/Server/IMqttClientSession.cs 查看文件

@@ -4,6 +4,10 @@ namespace MQTTnet.Server
{
public interface IMqttClientSession
{
/// <summary>
/// Gets the client identifier.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
/// </summary>
string ClientId { get; }

Task StopAsync();


+ 4
- 0
Source/MQTTnet/Server/IMqttServerOptions.cs 查看文件

@@ -4,6 +4,10 @@ namespace MQTTnet.Server
{
public interface IMqttServerOptions
{
/// <summary>
/// Gets the client identifier.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
/// </summary>
string ClientId { get; set; }

bool EnablePersistentSessions { get; }


+ 12
- 0
Source/MQTTnet/Server/IMqttServerPersistedSession.cs 查看文件

@@ -5,14 +5,26 @@ namespace MQTTnet.Server
{
public interface IMqttServerPersistedSession
{
/// <summary>
/// Gets the client identifier.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
/// </summary>
string ClientId { get; }

IDictionary<object, object> Items { get; }

IList<MqttTopicFilter> Subscriptions { get; }

/// <summary>
/// Gets the last will message.
/// In MQTT, you use the last will message feature to notify other clients about an ungracefully disconnected client.
/// </summary>
MqttApplicationMessage WillMessage { get; }

/// <summary>
/// Gets the will delay interval.
/// This is the time between the client disconnect and the time the will message will be sent.
/// </summary>
uint? WillDelayInterval { get; }

DateTime? SessionExpiryTimestamp { get; }


+ 4
- 0
Source/MQTTnet/Server/MqttApplicationMessageInterceptorContext.cs 查看文件

@@ -18,6 +18,10 @@ namespace MQTTnet.Server
/// </summary>
public IMqttNetScopedLogger Logger { get; }

/// <summary>
/// Gets the client identifier.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
/// </summary>
public string ClientId { get; }

public MqttApplicationMessage ApplicationMessage { get; set; }


+ 8
- 0
Source/MQTTnet/Server/MqttClientMessageQueueInterceptorContext.cs 查看文件

@@ -20,6 +20,14 @@ namespace MQTTnet.Server

public bool AcceptEnqueue { get; set; } = true;

/// <summary>
/// Gets or sets the supscription quality of service level.
/// The Quality of Service (QoS) level is an agreement between the sender of a message and the receiver of a message that defines the guarantee of delivery for a specific message.
/// There are 3 QoS levels in MQTT:
/// - At most once (0): Message gets delivered no time, once or multiple times.
/// - At least once (1): Message gets delivered at least once (one time or more often).
/// - Exactly once (2): Message gets delivered exactly once (It's ensured that the message only comes once).
/// </summary>
public MqttQualityOfServiceLevel SubscriptionQualityOfServiceLevel { get; set; }
}
}

+ 75
- 1
Source/MQTTnet/Server/MqttConnectionValidatorContext.cs 查看文件

@@ -21,6 +21,10 @@ namespace MQTTnet.Server
SessionItems = sessionItems;
}

/// <summary>
/// Gets the client identifier.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
/// </summary>
public string ClientId => _connectPacket.ClientId;

public string Endpoint => _clientAdapter.Endpoint;
@@ -37,30 +41,88 @@ namespace MQTTnet.Server

public string Password => Encoding.UTF8.GetString(RawPassword ?? new byte[0]);

/// <summary>
/// Gets or sets the will delay interval.
/// This is the time between the client disconnect and the time the will message will be sent.
/// </summary>
public MqttApplicationMessage WillMessage => _connectPacket?.WillMessage;

/// <summary>
/// Gets or sets a value indicating whether clean sessions are used or not.
/// When a client connects to a broker it can connect using either a non persistent connection (clean session) or a persistent connection.
/// With a non persistent connection the broker doesn't store any subscription information or undelivered messages for the client.
/// This mode is ideal when the client only publishes messages.
/// It can also connect as a durable client using a persistent connection.
/// In this mode, the broker will store subscription information, and undelivered messages for the client.
/// </summary>
public bool? CleanSession => _connectPacket?.CleanSession;

/// <summary>
/// Gets or sets the keep alive period.
/// The connection is normally left open by the client so that is can send and receive data at any time.
/// If no data flows over an open connection for a certain time period then the client will generate a PINGREQ and expect to receive a PINGRESP from the broker.
/// This message exchange confirms that the connection is open and working.
/// This period is known as the keep alive period.
/// </summary>
public ushort? KeepAlivePeriod => _connectPacket?.KeepAlivePeriod;

/// <summary>
/// Gets or sets the user properties.
/// In MQTT 5, user properties are basic UTF-8 string key-value pairs that you can append to almost every type of MQTT packet.
/// As long as you don’t exceed the maximum message size, you can use an unlimited number of user properties to add metadata to MQTT messages and pass information between publisher, broker, and subscriber.
/// The feature is very similar to the HTTP header concept.
/// Hint: MQTT 5 feature only.
/// </summary>
public List<MqttUserProperty> UserProperties => _connectPacket?.Properties?.UserProperties;

/// <summary>
/// Gets or sets the authentication data.
/// Hint: MQTT 5 feature only.
/// </summary>
public byte[] AuthenticationData => _connectPacket?.Properties?.AuthenticationData;

/// <summary>
/// Gets or sets the authentication method.
/// Hint: MQTT 5 feature only.
/// </summary>
public string AuthenticationMethod => _connectPacket?.Properties?.AuthenticationMethod;

public uint? MaximumPacketSize => _connectPacket?.Properties?.MaximumPacketSize;

/// <summary>
/// Gets or sets the receive maximum.
/// This gives the maximum length of the receive messages.
/// </summary>
public ushort? ReceiveMaximum => _connectPacket?.Properties?.ReceiveMaximum;

/// <summary>
/// Gets or sets the topic alias maximum.
/// This gives the maximum length of the topic alias.
/// </summary>
public ushort? TopicAliasMaximum => _connectPacket?.Properties?.TopicAliasMaximum;

/// <summary>
/// Gets the request problem information.
/// Hint: MQTT 5 feature only.
/// </summary>
public bool? RequestProblemInformation => _connectPacket?.Properties?.RequestProblemInformation;

/// <summary>
/// Gets the request response information.
/// Hint: MQTT 5 feature only.
/// </summary>
public bool? RequestResponseInformation => _connectPacket?.Properties?.RequestResponseInformation;

/// <summary>
/// Gets the session expiry interval.
/// The time after a session expires when it's not actively used.
/// </summary>
public uint? SessionExpiryInterval => _connectPacket?.Properties?.SessionExpiryInterval;

/// <summary>
/// Gets or sets the will delay interval.
/// This is the time between the client disconnect and the time the will message will be sent.
/// </summary>
public uint? WillDelayInterval => _connectPacket?.Properties?.WillDelayInterval;

/// <summary>
@@ -79,14 +141,26 @@ namespace MQTTnet.Server
}

/// <summary>
/// This is used for MQTTv5 only. When a MQTTv3 client connects the enum value must be one which is
/// Gets or sets the reason code. When a MQTTv3 client connects the enum value must be one which is
/// also supported in MQTTv3. Otherwise the connection attempt will fail because not all codes can be
/// converted properly.
/// Hint: MQTT 5 feature only.
/// </summary>
public MqttConnectReasonCode ReasonCode { get; set; } = MqttConnectReasonCode.Success;

/// <summary>
/// Gets or sets the response user properties.
/// In MQTT 5, user properties are basic UTF-8 string key-value pairs that you can append to almost every type of MQTT packet.
/// As long as you don’t exceed the maximum message size, you can use an unlimited number of user properties to add metadata to MQTT messages and pass information between publisher, broker, and subscriber.
/// The feature is very similar to the HTTP header concept.
/// Hint: MQTT 5 feature only.
/// </summary>
public List<MqttUserProperty> ResponseUserProperties { get; set; }

/// <summary>
/// Gets or sets the response authentication data.
/// Hint: MQTT 5 feature only.
/// </summary>
public byte[] ResponseAuthenticationData { get; set; }

public string AssignedClientIdentifier { get; set; }


+ 8
- 0
Source/MQTTnet/Server/MqttQueuedApplicationMessage.cs 查看文件

@@ -11,6 +11,14 @@ namespace MQTTnet.Server

public bool IsRetainedMessage { get; set; }

/// <summary>
/// Gets or sets the subscription quality of service level.
/// The Quality of Service (QoS) level is an agreement between the sender of a message and the receiver of a message that defines the guarantee of delivery for a specific message.
/// There are 3 QoS levels in MQTT:
/// - At most once (0): Message gets delivered no time, once or multiple times.
/// - At least once (1): Message gets delivered at least once (one time or more often).
/// - Exactly once (2): Message gets delivered exactly once (It's ensured that the message only comes once).
/// </summary>
public MqttQualityOfServiceLevel SubscriptionQualityOfServiceLevel { get; set; }

[Obsolete("Use 'SubscriptionQualityOfServiceLevel' instead.")]


+ 4
- 0
Source/MQTTnet/Server/MqttServerClientConnectedEventArgs.cs 查看文件

@@ -9,6 +9,10 @@ namespace MQTTnet.Server
ClientId = clientId ?? throw new ArgumentNullException(nameof(clientId));
}

/// <summary>
/// Gets the client identifier.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
/// </summary>
public string ClientId { get; }
}
}

+ 5
- 1
Source/MQTTnet/Server/MqttServerClientDisconnectedEventArgs.cs 查看文件

@@ -9,7 +9,11 @@ namespace MQTTnet.Server
ClientId = clientId ?? throw new ArgumentNullException(nameof(clientId));
DisconnectType = disconnectType;
}

/// <summary>
/// Gets the client identifier.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
/// </summary>
public string ClientId { get; }

public MqttClientDisconnectType DisconnectType { get; }


+ 8
- 0
Source/MQTTnet/Server/MqttServerClientSubscribedTopicEventArgs.cs 查看文件

@@ -10,8 +10,16 @@ namespace MQTTnet.Server
TopicFilter = topicFilter ?? throw new ArgumentNullException(nameof(topicFilter));
}

/// <summary>
/// Gets the client identifier.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
/// </summary>
public string ClientId { get; }

/// <summary>
/// Gets the topic filter.
/// The topic filter can contain topics and wildcards.
/// </summary>
public MqttTopicFilter TopicFilter { get; }
}
}

+ 8
- 0
Source/MQTTnet/Server/MqttServerClientUnsubscribedTopicEventArgs.cs 查看文件

@@ -10,8 +10,16 @@ namespace MQTTnet.Server
TopicFilter = topicFilter ?? throw new ArgumentNullException(nameof(topicFilter));
}

/// <summary>
/// Gets the client identifier.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
/// </summary>
public string ClientId { get; }

/// <summary>
/// Gets or sets the topic filter.
/// The topic filter can contain topics and wildcards.
/// </summary>
public string TopicFilter { get; }
}
}

+ 4
- 0
Source/MQTTnet/Server/MqttServerOptions.cs 查看文件

@@ -8,6 +8,10 @@ namespace MQTTnet.Server

public MqttServerTlsTcpEndpointOptions TlsEndpointOptions { get; } = new MqttServerTlsTcpEndpointOptions();

/// <summary>
/// Gets or sets the client identifier.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
/// </summary>
public string ClientId { get; set; }

public bool EnablePersistentSessions { get; set; }


+ 8
- 0
Source/MQTTnet/Server/MqttSubscriptionInterceptorContext.cs 查看文件

@@ -11,8 +11,16 @@ namespace MQTTnet.Server
SessionItems = sessionItems;
}

/// <summary>
/// Gets the client identifier.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
/// </summary>
public string ClientId { get; }

/// <summary>
/// Gets or sets the topic filter.
/// The topic filter can contain topics and wildcards.
/// </summary>
public MqttTopicFilter TopicFilter { get; set; }

/// <summary>


+ 9
- 0
Source/MQTTnet/Server/MqttUnsubscriptionInterceptorContext.cs 查看文件

@@ -11,8 +11,17 @@ namespace MQTTnet.Server
SessionItems = sessionItems;
}

/// <summary>
/// Gets the client identifier.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
/// </summary>
public string ClientId { get; }

/// <summary>
/// Gets or sets the MQTT topic.
/// In MQTT, the word topic refers to an UTF-8 string that the broker uses to filter messages for each connected client.
/// The topic consists of one or more topic levels. Each topic level is separated by a forward slash (topic level separator).
/// </summary>
public string Topic { get; set; }

/// <summary>


+ 4
- 0
Source/MQTTnet/Server/Status/IMqttClientStatus.cs 查看文件

@@ -6,6 +6,10 @@ namespace MQTTnet.Server.Status
{
public interface IMqttClientStatus
{
/// <summary>
/// Gets the client identifier.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
/// </summary>
string ClientId { get; }

string Endpoint { get; }


+ 4
- 0
Source/MQTTnet/Server/Status/IMqttSessionStatus.cs 查看文件

@@ -5,6 +5,10 @@ namespace MQTTnet.Server.Status
{
public interface IMqttSessionStatus
{
/// <summary>
/// Gets the client identifier.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
/// </summary>
string ClientId { get; }

long PendingApplicationMessagesCount { get; }


+ 4
- 0
Source/MQTTnet/Server/Status/MqttClientStatus.cs 查看文件

@@ -14,6 +14,10 @@ namespace MQTTnet.Server.Status
_connection = connection ?? throw new ArgumentNullException(nameof(connection));
}

/// <summary>
/// Gets or sets the client identifier.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
/// </summary>
public string ClientId { get; set; }

public string Endpoint { get; set; }


+ 4
- 0
Source/MQTTnet/Server/Status/MqttSessionStatus.cs 查看文件

@@ -15,6 +15,10 @@ namespace MQTTnet.Server.Status
_sessionsManager = sessionsManager ?? throw new ArgumentNullException(nameof(sessionsManager));
}

/// <summary>
/// Gets or sets the client identifier.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
/// </summary>
public string ClientId { get; set; }

public long PendingApplicationMessagesCount { get; set; }


Loading…
取消
儲存