mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-18 18:43:10 +08:00
Added client documentation.
This commit is contained in:
@@ -16,36 +16,95 @@ namespace MQTTnet.Extensions.ManagedClient
|
||||
/// </summary>
|
||||
IMqttClient InternalClient { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the client is started or not.
|
||||
/// </summary>
|
||||
bool IsStarted { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the client is connected or not.
|
||||
/// </summary>
|
||||
bool IsConnected { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a pending application message count.
|
||||
/// </summary>
|
||||
int PendingApplicationMessagesCount { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the MQTT client options.
|
||||
/// </summary>
|
||||
IManagedMqttClientOptions Options { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the connected handler.
|
||||
/// </summary>
|
||||
IMqttClientConnectedHandler ConnectedHandler { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the disconnected handler.
|
||||
/// </summary>
|
||||
IMqttClientDisconnectedHandler DisconnectedHandler { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the application message process handler.
|
||||
/// </summary>
|
||||
IApplicationMessageProcessedHandler ApplicationMessageProcessedHandler { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the application message skipped handler.
|
||||
/// </summary>
|
||||
IApplicationMessageSkippedHandler ApplicationMessageSkippedHandler { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the connecting failed handler.
|
||||
/// </summary>
|
||||
IConnectingFailedHandler ConnectingFailedHandler { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the synchronizing subscriptions failed handler.
|
||||
/// </summary>
|
||||
ISynchronizingSubscriptionsFailedHandler SynchronizingSubscriptionsFailedHandler { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Starts the client.
|
||||
/// </summary>
|
||||
/// <param name="options">The options.</param>
|
||||
/// <returns>A <see cref="Task"/> representing any asynchronous operation.</returns>
|
||||
Task StartAsync(IManagedMqttClientOptions options);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Stops the client.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="Task"/> representing any asynchronous operation.</returns>
|
||||
Task StopAsync();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Pings the server.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">A token to cancel the task.</param>
|
||||
/// <returns>A <see cref="Task"/> representing any asynchronous operation.</returns>
|
||||
Task PingAsync(CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Subscribes the client.
|
||||
/// </summary>
|
||||
/// <param name="topicFilters">The topic filters.</param>
|
||||
/// <returns>A <see cref="Task"/> representing any asynchronous operation.</returns>
|
||||
Task SubscribeAsync(IEnumerable<MqttTopicFilter> topicFilters);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Unsubscribes the client.
|
||||
/// </summary>
|
||||
/// <param name="topics">The topics.</param>
|
||||
/// <returns>A <see cref="Task"/> representing any asynchronous operation.</returns>
|
||||
Task UnsubscribeAsync(IEnumerable<string> topics);
|
||||
|
||||
/// <summary>
|
||||
/// Publishes a message from the client.
|
||||
/// </summary>
|
||||
/// <param name="applicationMessages">The application messages.</param>
|
||||
/// <returns>A <see cref="Task"/> representing any asynchronous operation.</returns>
|
||||
Task PublishAsync(ManagedMqttApplicationMessage applicationMessages);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,11 @@ namespace MQTTnet.Client.Connecting
|
||||
{
|
||||
public interface IMqttClientConnectedHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles the events when a client gets connected.
|
||||
/// </summary>
|
||||
/// <param name="eventArgs">The event args.</param>
|
||||
/// <returns>A <see cref="Task"/> representing any asynchronous operation.</returns>
|
||||
Task HandleConnectedAsync(MqttClientConnectedEventArgs eventArgs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,42 +7,110 @@ 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; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the session is present or not.
|
||||
/// </summary>
|
||||
public bool IsSessionPresent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether wildcard subscriptions are available.
|
||||
/// </summary>
|
||||
public bool? WildcardSubscriptionAvailable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether retained messages are available.
|
||||
/// </summary>
|
||||
public bool? RetainAvailable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the assigned client identifier.
|
||||
/// </summary>
|
||||
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; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the maximum packet size.
|
||||
/// </summary>
|
||||
public uint? MaximumPacketSize { 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 receive maximum.
|
||||
/// </summary>
|
||||
public ushort? ReceiveMaximum { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the maximum quality od service level.
|
||||
/// </summary>
|
||||
public MqttQualityOfServiceLevel MaximumQoS { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the response information.
|
||||
/// Hint: MQTT 5 feature only.
|
||||
/// </summary>
|
||||
public string ResponseInformation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the topic alias maximum.
|
||||
/// </summary>
|
||||
public ushort? TopicAliasMaximum { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the server reference.
|
||||
/// </summary>
|
||||
public string ServerReference { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the server keep alive.
|
||||
/// </summary>
|
||||
public ushort? ServerKeepAlive { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the session expiry interval.
|
||||
/// </summary>
|
||||
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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,11 @@ namespace MQTTnet.Client.Disconnecting
|
||||
{
|
||||
public interface IMqttClientDisconnectedHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles the events when a client gets disconnected.
|
||||
/// </summary>
|
||||
/// <param name="eventArgs">The event args.</param>
|
||||
/// <returns>A <see cref="Task"/> representing any asynchronous operation.</returns>
|
||||
Task HandleDisconnectedAsync(MqttClientDisconnectedEventArgs eventArgs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,16 @@
|
||||
{
|
||||
public 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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,12 +15,26 @@ namespace MQTTnet.Client.Disconnecting
|
||||
ReasonCode = reason;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the client was connected or not.
|
||||
/// </summary>
|
||||
public bool ClientWasConnected { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the exception.
|
||||
/// </summary>
|
||||
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!")]
|
||||
|
||||
+5
@@ -4,6 +4,11 @@ namespace MQTTnet.Client.ExtendedAuthenticationExchange
|
||||
{
|
||||
public interface IMqttExtendedAuthenticationExchangeHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles the authentication request.
|
||||
/// </summary>
|
||||
/// <param name="context">The context.</param>
|
||||
/// <returns>A <see cref="Task"/> representing any asynchronous operation.</returns>
|
||||
Task HandleRequestAsync(MqttExtendedAuthenticationExchangeContext context);
|
||||
}
|
||||
}
|
||||
|
||||
+26
@@ -20,16 +20,42 @@ 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; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the client.
|
||||
/// </summary>
|
||||
public IMqttClient Client { get; }
|
||||
}
|
||||
}
|
||||
|
||||
+21
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,19 +12,75 @@ namespace MQTTnet.Client
|
||||
{
|
||||
public interface IMqttClient : IApplicationMessageReceiver, IApplicationMessagePublisher, IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the client is connected or not.
|
||||
/// </summary>
|
||||
bool IsConnected { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the options.
|
||||
/// This contains all the set options for the client.
|
||||
/// </summary>
|
||||
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; }
|
||||
|
||||
/// <summary>
|
||||
/// Connects the client to the server using the specified options.
|
||||
/// </summary>
|
||||
/// <param name="options">The options that can be used on connect.</param>
|
||||
/// <param name="cancellationToken">A cancellation token to stop the task.</param>
|
||||
/// <returns>A result containing the authentication result information.</returns>
|
||||
Task<MqttClientAuthenticateResult> ConnectAsync(IMqttClientOptions options, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Disconnects the client from the server.
|
||||
/// </summary>
|
||||
/// <param name="options">The options containing a disconnect reason.</param>
|
||||
/// <param name="cancellationToken">A cancellation token to stop the task.</param>
|
||||
/// <returns>A <see cref="Task"/> representing any asynchronous operation.</returns>
|
||||
Task DisconnectAsync(MqttClientDisconnectOptions options, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Pings the server.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">A cancellation token to stop the task.</param>
|
||||
/// <returns>A <see cref="Task"/> representing any asynchronous operation.</returns>
|
||||
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);
|
||||
|
||||
/// <summary>
|
||||
/// Subscribes the client to topics.
|
||||
/// </summary>
|
||||
/// <param name="options">The subscription options.</param>
|
||||
/// <param name="cancellationToken">A cancellation token to stop the task.</param>
|
||||
/// <returns>A <see cref="Task"/> representing any asynchronous operation.</returns>
|
||||
Task<MqttClientSubscribeResult> SubscribeAsync(MqttClientSubscribeOptions options, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Unsubscribes the client from topics.
|
||||
/// </summary>
|
||||
/// <param name="options">The unsubscription options.</param>
|
||||
/// <param name="cancellationToken">A cancellation token to stop the task.</param>
|
||||
/// <returns>A <see cref="Task"/> representing any asynchronous operation.</returns>
|
||||
Task<MqttClientUnsubscribeResult> UnsubscribeAsync(MqttClientUnsubscribeOptions options, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using MQTTnet.Adapter;
|
||||
using MQTTnet.Adapter;
|
||||
using MQTTnet.Diagnostics;
|
||||
using MQTTnet.LowLevelClient;
|
||||
|
||||
@@ -7,22 +6,67 @@ namespace MQTTnet.Client
|
||||
{
|
||||
public interface IMqttClientFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// A method to tell the client to use the adapter factory.
|
||||
/// </summary>
|
||||
/// <param name="clientAdapterFactory">The client adapter factory.</param>
|
||||
/// <returns>A new <see cref="IMqttFactory"/>.</returns>
|
||||
IMqttFactory UseClientAdapterFactory(IMqttClientAdapterFactory clientAdapterFactory);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new low level MQTT client.
|
||||
/// </summary>
|
||||
/// <returns>A new <see cref="ILowLevelMqttClient"/>.</returns>
|
||||
ILowLevelMqttClient CreateLowLevelMqttClient();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new low level MQTT client.
|
||||
/// </summary>
|
||||
/// <param name="logger">The logger.</param>
|
||||
/// <returns>A new <see cref="ILowLevelMqttClient"/>.</returns>
|
||||
ILowLevelMqttClient CreateLowLevelMqttClient(IMqttNetLogger logger);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new low level MQTT client.
|
||||
/// </summary>
|
||||
/// <param name="clientAdapterFactory">The client adapter factory.</param>
|
||||
/// <returns>A new <see cref="ILowLevelMqttClient"/>.</returns>
|
||||
ILowLevelMqttClient CreateLowLevelMqttClient(IMqttClientAdapterFactory clientAdapterFactory);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new low level MQTT client.
|
||||
/// </summary>
|
||||
/// <param name="logger">The logger.</param>
|
||||
/// <param name="clientAdapterFactory">The client adapter factory.</param>
|
||||
/// <returns>A new <see cref="ILowLevelMqttClient"/>.</returns>
|
||||
ILowLevelMqttClient CreateLowLevelMqttClient(IMqttNetLogger logger, IMqttClientAdapterFactory clientAdapterFactory);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new MQTT client.
|
||||
/// </summary>
|
||||
/// <returns>A new <see cref="IMqttClient"/>.</returns>
|
||||
IMqttClient CreateMqttClient();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new MQTT client.
|
||||
/// </summary>
|
||||
/// <param name="logger">The logger.</param>
|
||||
/// <returns>A new <see cref="IMqttClient"/>.</returns>
|
||||
IMqttClient CreateMqttClient(IMqttNetLogger logger);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new MQTT client.
|
||||
/// </summary>
|
||||
/// <param name="adapterFactory">The adapter factory.</param>
|
||||
/// <returns>A new <see cref="IMqttClient"/>.</returns>
|
||||
IMqttClient CreateMqttClient(IMqttClientAdapterFactory adapterFactory);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new MQTT client.
|
||||
/// </summary>
|
||||
/// <param name="logger">The logger.</param>
|
||||
/// <param name="adapterFactory">The adapter factory.</param>
|
||||
/// <returns>A new <see cref="IMqttClient"/>.</returns>
|
||||
IMqttClient CreateMqttClient(IMqttNetLogger logger, IMqttClientAdapterFactory adapterFactory);
|
||||
}
|
||||
}
|
||||
@@ -8,26 +8,122 @@ 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; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the credentials.
|
||||
/// </summary>
|
||||
IMqttClientCredentials Credentials { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the extended authentication exchange handler.
|
||||
/// </summary>
|
||||
IMqttExtendedAuthenticationExchangeHandler ExtendedAuthenticationExchangeHandler { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the protocol version.
|
||||
/// </summary>
|
||||
MqttProtocolVersion ProtocolVersion { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the channel options.
|
||||
/// </summary>
|
||||
IMqttClientChannelOptions ChannelOptions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the timeout the communication uses.
|
||||
/// </summary>
|
||||
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; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum packet size.
|
||||
/// </summary>
|
||||
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; }
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,24 @@ namespace MQTTnet.Client.Options
|
||||
{
|
||||
public class MqttClientCertificateValidationCallbackContext
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the certificate.
|
||||
/// </summary>
|
||||
public X509Certificate Certificate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the certificate chain.
|
||||
/// </summary>
|
||||
public X509Chain Chain { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the SSL policy errors.
|
||||
/// </summary>
|
||||
public SslPolicyErrors SslPolicyErrors { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the client options.
|
||||
/// </summary>
|
||||
public IMqttClientChannelOptions ClientOptions { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,28 +8,122 @@ 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;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the credentials.
|
||||
/// </summary>
|
||||
public IMqttClientCredentials Credentials { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the extended authentication exchange handler.
|
||||
/// </summary>
|
||||
public IMqttExtendedAuthenticationExchangeHandler ExtendedAuthenticationExchangeHandler { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the protocol version.
|
||||
/// </summary>
|
||||
public MqttProtocolVersion ProtocolVersion { get; set; } = MqttProtocolVersion.V311;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the channel options.
|
||||
/// </summary>
|
||||
public IMqttClientChannelOptions ChannelOptions { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the timeout the communication uses.
|
||||
/// </summary>
|
||||
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; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the maximum packet size.
|
||||
/// </summary>
|
||||
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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,11 @@ namespace MQTTnet.Client.Options
|
||||
MqttClientOptionsBuilderTlsParameters _tlsParameters;
|
||||
MqttClientWebSocketProxyOptions _proxyOptions;
|
||||
|
||||
/// <summary>
|
||||
/// Adds the protocol version to the MQTT client options.
|
||||
/// </summary>
|
||||
/// <param name="value">The protocol version.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttClientOptionsBuilder"/> class.</returns>
|
||||
public MqttClientOptionsBuilder WithProtocolVersion(MqttProtocolVersion value)
|
||||
{
|
||||
if (value == MqttProtocolVersion.Unknown)
|
||||
@@ -28,47 +33,88 @@ namespace MQTTnet.Client.Options
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the communication timeout to the MQTT client options.
|
||||
/// </summary>
|
||||
/// <param name="value">The timeout.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttClientOptionsBuilder"/> class.</returns>
|
||||
public MqttClientOptionsBuilder WithCommunicationTimeout(TimeSpan value)
|
||||
{
|
||||
_options.CommunicationTimeout = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the clean session flag to the MQTT client options.
|
||||
/// </summary>
|
||||
/// <param name="value">The clean session flag.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttClientOptionsBuilder"/> class.</returns>
|
||||
public MqttClientOptionsBuilder WithCleanSession(bool value = true)
|
||||
{
|
||||
_options.CleanSession = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the keep alive send interval to the MQTT client options.
|
||||
/// </summary>
|
||||
/// <param name="value">The keep alive interval.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttClientOptionsBuilder"/> class.</returns>
|
||||
[Obsolete("This method is no longer supported. The client will send ping requests just before the keep alive interval is going to elapse. As per MQTT RFC the serve has to wait 1.5 times the interval so we don't need this anymore.")]
|
||||
public MqttClientOptionsBuilder WithKeepAliveSendInterval(TimeSpan value)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds no keep alive period to the MQTT client options.
|
||||
/// </summary>
|
||||
/// <returns>A new instance of the <see cref="MqttClientOptionsBuilder"/> class.</returns>
|
||||
public MqttClientOptionsBuilder WithNoKeepAlive()
|
||||
{
|
||||
return WithKeepAlivePeriod(TimeSpan.Zero);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the keep alive period to the MQTT client options.
|
||||
/// </summary>
|
||||
/// <param name="value">The keep alive period.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttClientOptionsBuilder"/> class.</returns>
|
||||
public MqttClientOptionsBuilder WithKeepAlivePeriod(TimeSpan value)
|
||||
{
|
||||
_options.KeepAlivePeriod = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the client identifier to the MQTT client options.
|
||||
/// </summary>
|
||||
/// <param name="value">The client identifier.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttClientOptionsBuilder"/> class.</returns>
|
||||
public MqttClientOptionsBuilder WithClientId(string value)
|
||||
{
|
||||
_options.ClientId = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the will message to the MQTT client options.
|
||||
/// </summary>
|
||||
/// <param name="value">The will message.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttClientOptionsBuilder"/> class.</returns>
|
||||
public MqttClientOptionsBuilder WithWillMessage(MqttApplicationMessage value)
|
||||
{
|
||||
_options.WillMessage = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the authentication to the MQTT client options.
|
||||
/// Hint: MQTT 5 feature only.
|
||||
/// </summary>
|
||||
/// <param name="method">The authentication method.</param>
|
||||
/// <param name="data">The data.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttClientOptionsBuilder"/> class.</returns>
|
||||
public MqttClientOptionsBuilder WithAuthentication(string method, byte[] data)
|
||||
{
|
||||
_options.AuthenticationMethod = method;
|
||||
@@ -76,48 +122,92 @@ namespace MQTTnet.Client.Options
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the will delay interval to the MQTT client options.
|
||||
/// </summary>
|
||||
/// <param name="willDelayInterval">The will delay interval.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttClientOptionsBuilder"/> class.</returns>
|
||||
public MqttClientOptionsBuilder WithWillDelayInterval(uint? willDelayInterval)
|
||||
{
|
||||
_options.WillDelayInterval = willDelayInterval;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the topic alias maximum to the MQTT client options.
|
||||
/// </summary>
|
||||
/// <param name="topicAliasMaximum">The topic alias maximum.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttClientOptionsBuilder"/> class.</returns>
|
||||
public MqttClientOptionsBuilder WithTopicAliasMaximum(ushort? topicAliasMaximum)
|
||||
{
|
||||
_options.TopicAliasMaximum = topicAliasMaximum;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the maximum packet size to the MQTT client options.
|
||||
/// </summary>
|
||||
/// <param name="maximumPacketSize">The maximum packet size.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttClientOptionsBuilder"/> class.</returns>
|
||||
public MqttClientOptionsBuilder WithMaximumPacketSize(uint? maximumPacketSize)
|
||||
{
|
||||
_options.MaximumPacketSize = maximumPacketSize;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the receive maximum to the MQTT client options.
|
||||
/// </summary>
|
||||
/// <param name="receiveMaximum">The receive maximum.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttClientOptionsBuilder"/> class.</returns>
|
||||
public MqttClientOptionsBuilder WithReceiveMaximum(ushort? receiveMaximum)
|
||||
{
|
||||
_options.ReceiveMaximum = receiveMaximum;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the request problem information to the MQTT client options.
|
||||
/// Hint: MQTT 5 feature only.
|
||||
/// </summary>
|
||||
/// <param name="requestProblemInformation">The request problem information.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttClientOptionsBuilder"/> class.</returns>
|
||||
public MqttClientOptionsBuilder WithRequestProblemInformation(bool? requestProblemInformation = true)
|
||||
{
|
||||
_options.RequestProblemInformation = requestProblemInformation;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the request response information to the MQTT client options.
|
||||
/// Hint: MQTT 5 feature only.
|
||||
/// </summary>
|
||||
/// <param name="requestResponseInformation">The request response information.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttClientOptionsBuilder"/> class.</returns>
|
||||
public MqttClientOptionsBuilder WithRequestResponseInformation(bool? requestResponseInformation = true)
|
||||
{
|
||||
_options.RequestResponseInformation = requestResponseInformation;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the session expiry interval to the MQTT client options.
|
||||
/// </summary>
|
||||
/// <param name="sessionExpiryInterval">The session expiry interval.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttClientOptionsBuilder"/> class.</returns>
|
||||
public MqttClientOptionsBuilder WithSessionExpiryInterval(uint? sessionExpiryInterval)
|
||||
{
|
||||
_options.SessionExpiryInterval = sessionExpiryInterval;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the user property to the MQTT client options.
|
||||
/// Hint: MQTT 5 feature only.
|
||||
/// </summary>
|
||||
/// <param name="name">The user property name.</param>
|
||||
/// <param name="value">The user property value.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttClientOptionsBuilder"/> class.</returns>
|
||||
public MqttClientOptionsBuilder WithUserProperty(string name, string value)
|
||||
{
|
||||
if (name is null) throw new ArgumentNullException(nameof(name));
|
||||
@@ -132,6 +222,12 @@ namespace MQTTnet.Client.Options
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the credentials to the MQTT client options.
|
||||
/// </summary>
|
||||
/// <param name="username">The user name.</param>
|
||||
/// <param name="password">The password.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttClientOptionsBuilder"/> class.</returns>
|
||||
public MqttClientOptionsBuilder WithCredentials(string username, string password = null)
|
||||
{
|
||||
byte[] passwordBuffer = null;
|
||||
@@ -144,6 +240,12 @@ namespace MQTTnet.Client.Options
|
||||
return WithCredentials(username, passwordBuffer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the credentials to the MQTT client options.
|
||||
/// </summary>
|
||||
/// <param name="username">The user name.</param>
|
||||
/// <param name="password">The password.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttClientOptionsBuilder"/> class.</returns>
|
||||
public MqttClientOptionsBuilder WithCredentials(string username, byte[] password = null)
|
||||
{
|
||||
_options.Credentials = new MqttClientCredentials
|
||||
@@ -155,6 +257,11 @@ namespace MQTTnet.Client.Options
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the credentials to the MQTT client options.
|
||||
/// </summary>
|
||||
/// <param name="credentials">The credentials.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttClientOptionsBuilder"/> class.</returns>
|
||||
public MqttClientOptionsBuilder WithCredentials(IMqttClientCredentials credentials)
|
||||
{
|
||||
_options.Credentials = credentials;
|
||||
@@ -162,12 +269,23 @@ namespace MQTTnet.Client.Options
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a extended authentication exchange handler to the MQTT client options.
|
||||
/// </summary>
|
||||
/// <param name="handler">The handler.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttClientOptionsBuilder"/> class.</returns>
|
||||
public MqttClientOptionsBuilder WithExtendedAuthenticationExchangeHandler(IMqttExtendedAuthenticationExchangeHandler handler)
|
||||
{
|
||||
_options.ExtendedAuthenticationExchangeHandler = handler;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a TCP server connection to the MQTT client options.
|
||||
/// </summary>
|
||||
/// <param name="server">The server.</param>
|
||||
/// <param name="port">The port.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttClientOptionsBuilder"/> class.</returns>
|
||||
public MqttClientOptionsBuilder WithTcpServer(string server, int? port = null)
|
||||
{
|
||||
_tcpOptions = new MqttClientTcpOptions
|
||||
@@ -179,6 +297,11 @@ namespace MQTTnet.Client.Options
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a TCP server connection to the MQTT client options.
|
||||
/// </summary>
|
||||
/// <param name="optionsBuilder">The options builder.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttClientOptionsBuilder"/> class.</returns>
|
||||
// TODO: Consider creating _MqttClientTcpOptionsBuilder_ as overload.
|
||||
public MqttClientOptionsBuilder WithTcpServer(Action<MqttClientTcpOptions> optionsBuilder)
|
||||
{
|
||||
@@ -190,6 +313,16 @@ namespace MQTTnet.Client.Options
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a proxy connection to the MQTT client options.
|
||||
/// </summary>
|
||||
/// <param name="address">The address.</param>
|
||||
/// <param name="username">The user name.</param>
|
||||
/// <param name="password">The password.</param>
|
||||
/// <param name="domain">The domain.</param>
|
||||
/// <param name="bypassOnLocal">The bypass on local flag.</param>
|
||||
/// <param name="bypassList">The bypass list.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttClientOptionsBuilder"/> class.</returns>
|
||||
public MqttClientOptionsBuilder WithProxy(string address, string username = null, string password = null, string domain = null, bool bypassOnLocal = false, string[] bypassList = null)
|
||||
{
|
||||
_proxyOptions = new MqttClientWebSocketProxyOptions
|
||||
@@ -205,6 +338,11 @@ namespace MQTTnet.Client.Options
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a proxy connection to the MQTT client options.
|
||||
/// </summary>
|
||||
/// <param name="optionsBuilder">The options builder.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttClientOptionsBuilder"/> class.</returns>
|
||||
public MqttClientOptionsBuilder WithProxy(Action<MqttClientWebSocketProxyOptions> optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder == null) throw new ArgumentNullException(nameof(optionsBuilder));
|
||||
@@ -214,6 +352,12 @@ namespace MQTTnet.Client.Options
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a web socket server to the MQTT client options.
|
||||
/// </summary>
|
||||
/// <param name="uri">The uri.</param>
|
||||
/// <param name="parameters">The parameters.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttClientOptionsBuilder"/> class.</returns>
|
||||
public MqttClientOptionsBuilder WithWebSocketServer(string uri, MqttClientOptionsBuilderWebSocketParameters parameters = null)
|
||||
{
|
||||
_webSocketOptions = new MqttClientWebSocketOptions
|
||||
@@ -226,6 +370,11 @@ namespace MQTTnet.Client.Options
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a web socket server to the MQTT client options.
|
||||
/// </summary>
|
||||
/// <param name="optionsBuilder">The options builder.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttClientOptionsBuilder"/> class.</returns>
|
||||
public MqttClientOptionsBuilder WithWebSocketServer(Action<MqttClientWebSocketOptions> optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder == null) throw new ArgumentNullException(nameof(optionsBuilder));
|
||||
@@ -236,17 +385,31 @@ namespace MQTTnet.Client.Options
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds TLS to the MQTT client options.
|
||||
/// </summary>
|
||||
/// <param name="parameters">The parameters.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttClientOptionsBuilder"/> class.</returns>
|
||||
public MqttClientOptionsBuilder WithTls(MqttClientOptionsBuilderTlsParameters parameters)
|
||||
{
|
||||
_tlsParameters = parameters;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds TLS to the MQTT client options.
|
||||
/// </summary>
|
||||
/// <returns>A new instance of the <see cref="MqttClientOptionsBuilder"/> class.</returns>
|
||||
public MqttClientOptionsBuilder WithTls()
|
||||
{
|
||||
return WithTls(new MqttClientOptionsBuilderTlsParameters { UseTls = true });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds TLS to the MQTT client options.
|
||||
/// </summary>
|
||||
/// <param name="optionsBuilder">The options builder.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttClientOptionsBuilder"/> class.</returns>
|
||||
public MqttClientOptionsBuilder WithTls(Action<MqttClientOptionsBuilderTlsParameters> optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder == null) throw new ArgumentNullException(nameof(optionsBuilder));
|
||||
@@ -256,6 +419,10 @@ namespace MQTTnet.Client.Options
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the MQTT client options.
|
||||
/// </summary>
|
||||
/// <returns>The <see cref="IMqttClientOptions"/>.</returns>
|
||||
public IMqttClientOptions Build()
|
||||
{
|
||||
if (_tcpOptions == null && _webSocketOptions == null)
|
||||
|
||||
@@ -6,12 +6,30 @@ namespace MQTTnet.Client.Publishing
|
||||
{
|
||||
public class MqttClientPublishResult
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the packet identifier.
|
||||
/// </summary>
|
||||
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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,11 @@ namespace MQTTnet.Client.Receiving
|
||||
{
|
||||
public interface IMqttApplicationMessageReceivedHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles the application message received event.
|
||||
/// </summary>
|
||||
/// <param name="eventArgs">The event args.</param>
|
||||
/// <returns>A <see cref="Task"/> representing any asynchronous operation.</returns>
|
||||
Task HandleApplicationMessageReceivedAsync(MqttApplicationMessageReceivedEventArgs eventArgs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
@@ -24,13 +31,26 @@ namespace MQTTnet.Client.Subscribing
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the subscription identifier to the subscribe options.
|
||||
/// </summary>
|
||||
/// <param name="subscriptionIdentifier">The subscription identifier.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttApplicationMessageBuilder"/> class.</returns>
|
||||
public MqttClientSubscribeOptionsBuilder WithSubscriptionIdentifier(uint? subscriptionIdentifier)
|
||||
{
|
||||
_subscribeOptions.SubscriptionIdentifier = subscriptionIdentifier;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a topic filter to the subscribe options.
|
||||
/// </summary>
|
||||
/// <param name="topic">The topic.</param>
|
||||
/// <param name="qualityOfServiceLevel">The quality of service level.</param>
|
||||
/// <param name="noLocal">A value indicating whether to not send messages originating on this client (noLocal) or not.</param>
|
||||
/// <param name="retainAsPublished">A value indicating whether messages are retained as published or not.</param>
|
||||
/// <param name="retainHandling">The retain handling.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttApplicationMessageBuilder"/> class.</returns>
|
||||
public MqttClientSubscribeOptionsBuilder WithTopicFilter(
|
||||
string topic,
|
||||
MqttQualityOfServiceLevel qualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce,
|
||||
@@ -48,6 +68,11 @@ namespace MQTTnet.Client.Subscribing
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the topic filter to the subscribe options.
|
||||
/// </summary>
|
||||
/// <param name="topicFilterBuilder">The topic filter builder.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttApplicationMessageBuilder"/> class.</returns>
|
||||
public MqttClientSubscribeOptionsBuilder WithTopicFilter(Action<MqttTopicFilterBuilder> topicFilterBuilder)
|
||||
{
|
||||
if (topicFilterBuilder == null) throw new ArgumentNullException(nameof(topicFilterBuilder));
|
||||
@@ -58,6 +83,11 @@ namespace MQTTnet.Client.Subscribing
|
||||
return WithTopicFilter(internalTopicFilterBuilder);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the topic filter to the subscribe options.
|
||||
/// </summary>
|
||||
/// <param name="topicFilterBuilder">The topic filter builder.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttApplicationMessageBuilder"/> class.</returns>
|
||||
public MqttClientSubscribeOptionsBuilder WithTopicFilter(MqttTopicFilterBuilder topicFilterBuilder)
|
||||
{
|
||||
if (topicFilterBuilder == null) throw new ArgumentNullException(nameof(topicFilterBuilder));
|
||||
@@ -65,6 +95,11 @@ namespace MQTTnet.Client.Subscribing
|
||||
return WithTopicFilter(topicFilterBuilder.Build());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the topic filter to the subscribe options.
|
||||
/// </summary>
|
||||
/// <param name="topicFilter">The topic filter.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttApplicationMessageBuilder"/> class.</returns>
|
||||
public MqttClientSubscribeOptionsBuilder WithTopicFilter(MqttTopicFilter topicFilter)
|
||||
{
|
||||
if (topicFilter == null) throw new ArgumentNullException(nameof(topicFilter));
|
||||
@@ -79,6 +114,10 @@ namespace MQTTnet.Client.Subscribing
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the subscription options.
|
||||
/// </summary>
|
||||
/// <returns>A new instance of the <see cref="MqttClientSubscribeOptions"/> class.</returns>
|
||||
public MqttClientSubscribeOptions Build()
|
||||
{
|
||||
return _subscribeOptions;
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
@@ -30,6 +43,11 @@ namespace MQTTnet.Client.Unsubscribing
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the topic filter to the unsubscribe options.
|
||||
/// </summary>
|
||||
/// <param name="topic">The topic.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttClientUnsubscribeOptionsBuilder"/> class.</returns>
|
||||
public MqttClientUnsubscribeOptionsBuilder WithTopicFilter(string topic)
|
||||
{
|
||||
if (topic is null) throw new ArgumentNullException(nameof(topic));
|
||||
@@ -44,6 +62,11 @@ namespace MQTTnet.Client.Unsubscribing
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the topic filter to the unsubscribe options.
|
||||
/// </summary>
|
||||
/// <param name="topicFilter">The topic filter.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttClientUnsubscribeOptionsBuilder"/> class.</returns>
|
||||
public MqttClientUnsubscribeOptionsBuilder WithTopicFilter(MqttTopicFilter topicFilter)
|
||||
{
|
||||
if (topicFilter is null) throw new ArgumentNullException(nameof(topicFilter));
|
||||
@@ -51,6 +74,10 @@ namespace MQTTnet.Client.Unsubscribing
|
||||
return WithTopicFilter(topicFilter.Topic);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the unsubscription options.
|
||||
/// </summary>
|
||||
/// <returns>A new instance of the <see cref="MqttClientUnsubscribeOptions"/> class.</returns>
|
||||
public MqttClientUnsubscribeOptions Build()
|
||||
{
|
||||
return _unsubscribeOptions;
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,12 @@ namespace MQTTnet
|
||||
{
|
||||
public interface IApplicationMessagePublisher
|
||||
{
|
||||
/// <summary>
|
||||
/// Publishes a new application message to the server.
|
||||
/// </summary>
|
||||
/// <param name="applicationMessage">The application message.</param>
|
||||
/// <param name="cancellationToken">A cancellation token to stop the task.</param>
|
||||
/// <returns>A <see cref="Task"/> representing any asynchronous operation.</returns>
|
||||
Task<MqttClientPublishResult> PublishAsync(MqttApplicationMessage applicationMessage, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,14 @@ namespace MQTTnet
|
||||
{
|
||||
public interface IMqttFactory : IMqttClientFactory, IMqttServerFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the default logger.
|
||||
/// </summary>
|
||||
IMqttNetLogger DefaultLogger { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the properties.
|
||||
/// </summary>
|
||||
IDictionary<object, object> Properties { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,31 +11,128 @@ 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;
|
||||
|
||||
/// <summary>
|
||||
/// Adds a topic to the message.
|
||||
/// </summary>
|
||||
/// <param name="topic">The topic.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttApplicationMessageBuilder"/> class.</returns>
|
||||
public MqttApplicationMessageBuilder WithTopic(string topic)
|
||||
{
|
||||
_topic = topic;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a payload to the message.
|
||||
/// </summary>
|
||||
/// <param name="payload">The payload.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttApplicationMessageBuilder"/> class.</returns>
|
||||
public MqttApplicationMessageBuilder WithPayload(byte[] payload)
|
||||
{
|
||||
_payload = payload;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a payload to the message.
|
||||
/// </summary>
|
||||
/// <param name="payload">The payload.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttApplicationMessageBuilder"/> class.</returns>
|
||||
public MqttApplicationMessageBuilder WithPayload(IEnumerable<byte> payload)
|
||||
{
|
||||
if (payload == null)
|
||||
@@ -54,6 +151,11 @@ namespace MQTTnet
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a payload to the message.
|
||||
/// </summary>
|
||||
/// <param name="payload">The payload.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttApplicationMessageBuilder"/> class.</returns>
|
||||
public MqttApplicationMessageBuilder WithPayload(Stream payload)
|
||||
{
|
||||
if (payload == null)
|
||||
@@ -65,6 +167,12 @@ namespace MQTTnet
|
||||
return WithPayload(payload, payload.Length - payload.Position);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a payload to the message.
|
||||
/// </summary>
|
||||
/// <param name="payload">The payload.</param>
|
||||
/// <param name="length">The stream length.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttApplicationMessageBuilder"/> class.</returns>
|
||||
public MqttApplicationMessageBuilder WithPayload(Stream payload, long length)
|
||||
{
|
||||
if (payload == null)
|
||||
@@ -86,6 +194,11 @@ namespace MQTTnet
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a payload to the message.
|
||||
/// </summary>
|
||||
/// <param name="payload">The payload.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttApplicationMessageBuilder"/> class.</returns>
|
||||
public MqttApplicationMessageBuilder WithPayload(string payload)
|
||||
{
|
||||
if (payload == null)
|
||||
@@ -98,12 +211,22 @@ namespace MQTTnet
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the quality of service level to the message.
|
||||
/// </summary>
|
||||
/// <param name="qualityOfServiceLevel">The quality of service level.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttApplicationMessageBuilder"/> class.</returns>
|
||||
public MqttApplicationMessageBuilder WithQualityOfServiceLevel(MqttQualityOfServiceLevel qualityOfServiceLevel)
|
||||
{
|
||||
_qualityOfServiceLevel = qualityOfServiceLevel;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the quality of service level to the message.
|
||||
/// </summary>
|
||||
/// <param name="qualityOfServiceLevel">The quality of service level.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttApplicationMessageBuilder"/> class.</returns>
|
||||
public MqttApplicationMessageBuilder WithQualityOfServiceLevel(int qualityOfServiceLevel)
|
||||
{
|
||||
if (qualityOfServiceLevel < 0 || qualityOfServiceLevel > 2)
|
||||
@@ -114,24 +237,40 @@ namespace MQTTnet
|
||||
return WithQualityOfServiceLevel((MqttQualityOfServiceLevel)qualityOfServiceLevel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds retain flag to the message.
|
||||
/// </summary>
|
||||
/// <returns>A new instance of the <see cref="MqttApplicationMessageBuilder"/> class.</returns>
|
||||
public MqttApplicationMessageBuilder WithRetainFlag(bool value = true)
|
||||
{
|
||||
_retain = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the quality of service level 0 (at least once) to the message.
|
||||
/// </summary>
|
||||
/// <returns>A new instance of the <see cref="MqttApplicationMessageBuilder"/> class.</returns>
|
||||
public MqttApplicationMessageBuilder WithAtLeastOnceQoS()
|
||||
{
|
||||
_qualityOfServiceLevel = MqttQualityOfServiceLevel.AtLeastOnce;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the quality of service level 1 (at most once) to the message.
|
||||
/// </summary>
|
||||
/// <returns>A new instance of the <see cref="MqttApplicationMessageBuilder"/> class.</returns>
|
||||
public MqttApplicationMessageBuilder WithAtMostOnceQoS()
|
||||
{
|
||||
_qualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the quality of service level 2 (exactly once) to the message.
|
||||
/// </summary>
|
||||
/// <returns>A new instance of the <see cref="MqttApplicationMessageBuilder"/> class.</returns>
|
||||
public MqttApplicationMessageBuilder WithExactlyOnceQoS()
|
||||
{
|
||||
_qualityOfServiceLevel = MqttQualityOfServiceLevel.ExactlyOnce;
|
||||
@@ -139,8 +278,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 +296,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 +307,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 +319,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 +331,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 +343,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 +360,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,14 +372,21 @@ 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;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the message.
|
||||
/// </summary>
|
||||
/// <returns>A new instance of the <see cref="MqttApplicationMessage"/> class.</returns>
|
||||
public MqttApplicationMessage Build()
|
||||
{
|
||||
if (!_topicAlias.HasValue && string.IsNullOrEmpty(_topic))
|
||||
|
||||
@@ -5,6 +5,11 @@ namespace MQTTnet
|
||||
{
|
||||
public static class MqttApplicationMessageExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts the payload to a string if possible.
|
||||
/// </summary>
|
||||
/// <param name="applicationMessage">The application message.</param>
|
||||
/// <returns>A string.</returns>
|
||||
public static string ConvertPayloadToString(this MqttApplicationMessage applicationMessage)
|
||||
{
|
||||
if (applicationMessage == null) throw new ArgumentNullException(nameof(applicationMessage));
|
||||
|
||||
@@ -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; }
|
||||
|
||||
|
||||
@@ -11,39 +11,79 @@ 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;
|
||||
|
||||
/// <summary>
|
||||
/// Adds a topic to the topic filter.
|
||||
/// </summary>
|
||||
/// <param name="topic">The topic.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttTopicFilterBuilder"/> class.</returns>
|
||||
public MqttTopicFilterBuilder WithTopic(string topic)
|
||||
{
|
||||
_topic = topic;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the quality of service level to the topic filter.
|
||||
/// </summary>
|
||||
/// <param name="qualityOfServiceLevel">The quality of service level.</param>
|
||||
/// <returns>A new instance of the <see cref="MqttTopicFilterBuilder"/> class.</returns>
|
||||
public MqttTopicFilterBuilder WithQualityOfServiceLevel(MqttQualityOfServiceLevel qualityOfServiceLevel)
|
||||
{
|
||||
_qualityOfServiceLevel = qualityOfServiceLevel;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the quality of service level 0 (at least once) to the topic filter.
|
||||
/// </summary>
|
||||
/// <returns>A new instance of the <see cref="MqttTopicFilterBuilder"/> class.</returns>
|
||||
public MqttTopicFilterBuilder WithAtLeastOnceQoS()
|
||||
{
|
||||
_qualityOfServiceLevel = MqttQualityOfServiceLevel.AtLeastOnce;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the quality of service level 1 (at most once) to the topic filter.
|
||||
/// </summary>
|
||||
/// <returns>A new instance of the <see cref="MqttTopicFilterBuilder"/> class.</returns>
|
||||
public MqttTopicFilterBuilder WithAtMostOnceQoS()
|
||||
{
|
||||
_qualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the quality of service level 2 (exactly once) to the topic filter.
|
||||
/// </summary>
|
||||
/// <returns>A new instance of the <see cref="MqttTopicFilterBuilder"/> class.</returns>
|
||||
public MqttTopicFilterBuilder WithExactlyOnceQoS()
|
||||
{
|
||||
_qualityOfServiceLevel = MqttQualityOfServiceLevel.ExactlyOnce;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the topic filter.
|
||||
/// </summary>
|
||||
/// <returns>A new instance of the <see cref="MqttTopicFilter"/> class.</returns>
|
||||
public MqttTopicFilter Build()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_topic))
|
||||
|
||||
@@ -7,14 +7,37 @@ namespace MQTTnet.Server
|
||||
{
|
||||
public interface IMqttServerFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the default server adapters.
|
||||
/// </summary>
|
||||
IList<Func<IMqttFactory, IMqttServerAdapter>> DefaultServerAdapters { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new default MQTT server.
|
||||
/// </summary>
|
||||
/// <returns>A new <see cref="IMqttServer"/>.</returns>
|
||||
IMqttServer CreateMqttServer();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new default MQTT server.
|
||||
/// </summary>
|
||||
/// <param name="logger">The logger.</param>
|
||||
/// <returns>A new <see cref="IMqttServer"/>.</returns>
|
||||
IMqttServer CreateMqttServer(IMqttNetLogger logger);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new default MQTT server.
|
||||
/// </summary>
|
||||
/// <param name="adapters">The adapters.</param>
|
||||
/// <returns>A new <see cref="IMqttServer"/>.</returns>
|
||||
IMqttServer CreateMqttServer(IEnumerable<IMqttServerAdapter> adapters);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new default MQTT server.
|
||||
/// </summary>
|
||||
/// <param name="adapters">The adapters.</param>
|
||||
/// <param name="logger">The logger.</param>
|
||||
/// <returns>A new <see cref="IMqttServer"/>.</returns>
|
||||
IMqttServer CreateMqttServer(IEnumerable<IMqttServerAdapter> adapters, IMqttNetLogger logger);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user