// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System; using System.Collections.Generic; using MQTTnet.Formatter; using MQTTnet.Packets; using MQTTnet.Protocol; namespace MQTTnet.Client { public sealed class MqttClientOptions { /// /// Usually the MQTT packets can be send partially. This is done by using multiple TCP packets /// or WebSocket frames etc. Unfortunately not all brokers (like Amazon Web Services (AWS)) do support this feature and /// will close the connection when receiving such packets. If such a service is used this flag must /// be set to _false_. /// public bool AllowPacketFragmentation { get; set; } = true; /// /// Gets or sets the authentication data. /// MQTT 5.0.0+ feature. /// public byte[] AuthenticationData { get; set; } /// /// Gets or sets the authentication method. /// MQTT 5.0.0+ feature. /// public string AuthenticationMethod { get; set; } public IMqttClientChannelOptions ChannelOptions { get; set; } /// /// 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. /// public bool CleanSession { get; set; } = true; /// /// Gets the client identifier. /// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues. /// public string ClientId { get; set; } = Guid.NewGuid().ToString("N"); public IMqttClientCredentialsProvider Credentials { get; set; } public IMqttExtendedAuthenticationExchangeHandler ExtendedAuthenticationExchangeHandler { get; set; } /// /// 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. /// public TimeSpan KeepAlivePeriod { get; set; } = TimeSpan.FromSeconds(15); /// /// Gets or sets the maximum packet size. /// MQTT 5.0.0+ feature. /// public uint MaximumPacketSize { get; set; } public MqttProtocolVersion ProtocolVersion { get; set; } = MqttProtocolVersion.V311; /// /// Gets or sets the receive maximum. /// This gives the maximum length of the receive messages. /// MQTT 5.0.0+ feature. /// public ushort ReceiveMaximum { get; set; } /// /// Gets or sets the request problem information. /// MQTT 5.0.0+ feature. /// public bool RequestProblemInformation { get; set; } = true; /// /// Gets or sets the request response information. /// MQTT 5.0.0+ feature. /// public bool RequestResponseInformation { get; set; } /// /// Gets or sets the session expiry interval. /// The time after a session expires when it's not actively used. /// MQTT 5.0.0+ feature. /// public uint SessionExpiryInterval { get; set; } /// /// Gets or sets whether an exception should be thrown when the server has sent a non success ACK packet. /// public bool ThrowOnNonSuccessfulConnectResponse { get; set; } = true; /// /// Gets or sets the timeout which will be applied at socket level and internal operations. /// The default value is the same as for sockets in .NET in general. /// public TimeSpan Timeout { get; set; } = TimeSpan.FromSeconds(100); /// /// Gets or sets the topic alias maximum. /// This gives the maximum length of the topic alias. /// MQTT 5.0.0+ feature. /// public ushort TopicAliasMaximum { get; set; } /// /// If set to true, the bridge will attempt to indicate to the remote broker that it is a bridge not an ordinary /// client. /// If successful, this means that loop detection will be more effective and that retained messages will be propagated /// correctly. /// /// Not all brokers support this feature so it may be necessary to set it to false if your bridge does not /// connect properly. /// /// public bool TryPrivate { get; set; } = true; /// /// 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. /// MQTT 5.0.0+ feature. /// public List UserProperties { get; set; } /// /// When this feature is enabled the client will check if used properties are supported in the selected protocol /// version. /// This feature can be validated if an application message is generated one time but sent via different protocol /// versions. /// Default values are applied if the validation is off and features are not supported. /// public bool ValidateFeatures { get; set; } = true; /// /// Gets or sets the content type of the will message. /// MQTT 5.0.0+ feature. /// public string WillContentType { get; set; } /// /// Gets or sets the correlation data of the will message. /// MQTT 5.0.0+ feature. /// public byte[] WillCorrelationData { get; set; } /// /// Gets or sets the will delay interval. /// This is the time between the client disconnect and the time the will message will be sent. /// MQTT 5.0.0+ feature. /// public uint WillDelayInterval { get; set; } /// /// Gets or sets the message expiry interval of the will message. /// MQTT 5.0.0+ feature. /// public uint WillMessageExpiryInterval { get; set; } /// /// Gets or sets the payload of the will message. /// public byte[] WillPayload { get; set; } /// /// Gets or sets the payload format indicator of the will message. /// MQTT 5.0.0+ feature. /// public MqttPayloadFormatIndicator WillPayloadFormatIndicator { get; set; } = MqttPayloadFormatIndicator.Unspecified; /// /// Gets or sets the QoS level of the will message. /// public MqttQualityOfServiceLevel WillQualityOfServiceLevel { get; set; } /// /// Gets or sets the response topic of the will message. /// MQTT 5.0.0+ feature. /// public string WillResponseTopic { get; set; } /// /// Gets or sets the retain flag of the will message. /// public bool WillRetain { get; set; } /// /// Gets or sets the topic of the will message. /// public string WillTopic { get; set; } /// /// Gets or sets the user properties of the will message. /// MQTT 5.0.0+ feature. /// public List WillUserProperties { get; set; } /// /// Gets or sets the default and initial size of the packet write buffer. /// It is recommended to set this to a value close to the usual expected packet size * 1.5. /// Do not change this value when no memory issues are experienced. /// public int WriterBufferSize { get; set; } = 4096; /// /// Gets or sets the maximum size of the buffer writer. The writer will reduce its internal buffer /// to this value after serializing a packet. /// Do not change this value when no memory issues are experienced. /// public int WriterBufferSizeMax { get; set; } = 65535; } }