Show / Hide Table of Contents

    Class MqttClientConfigurationBuilder

    Builds the MqttClientConfiguration.

    Inheritance
    object
    MqttClientConfigurationBuilder
    Inherited Members
    object.GetType()
    object.MemberwiseClone()
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    Namespace: Silverback.Messaging.Configuration.Mqtt
    Assembly: Silverback.Integration.MQTT.dll
    Syntax
    public class MqttClientConfigurationBuilder

    Constructors

    MqttClientConfigurationBuilder(IServiceProvider)

    Initializes a new instance of the MqttClientConfigurationBuilder class.

    Declaration
    public MqttClientConfigurationBuilder(IServiceProvider serviceProvider)
    Parameters
    Type Name Description
    IServiceProvider serviceProvider

    The IServiceProvider to be used to resolve the required services.

    Properties

    ServiceProvider

    Gets the IServiceProvider instance to be used to resolve the required services.

    Declaration
    public IServiceProvider ServiceProvider { get; }
    Property Value
    Type Description
    IServiceProvider

    Methods

    AddUserProperty(string, string?)

    Adds a user property to be sent with the CONNECT packet. It can be used to send connection related properties from the client to the server.

    Declaration
    public MqttClientConfigurationBuilder AddUserProperty(string name, string? value)
    Parameters
    Type Name Description
    string name

    The property name.

    string value

    The property value.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    AllowPacketFragmentation()

    Allow packet fragmentation. This is the default, use DisablePacketFragmentation() to turn it off.

    Declaration
    public MqttClientConfigurationBuilder AllowPacketFragmentation()
    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    Build()

    Builds the MqttClientConfiguration instance.

    Declaration
    public MqttClientConfiguration Build()
    Returns
    Type Description
    MqttClientConfiguration

    The MqttClientConfiguration.

    ConnectTo(string)

    Specifies the URI of the MQTT server.

    Declaration
    public MqttClientConfigurationBuilder ConnectTo(string serverUri)
    Parameters
    Type Name Description
    string serverUri

    The URI of the MQTT server.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    ConnectTo(Uri)

    Specifies the URI of the MQTT server.

    Declaration
    public MqttClientConfigurationBuilder ConnectTo(Uri serverUri)
    Parameters
    Type Name Description
    Uri serverUri

    The URI of the MQTT server.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    ConnectViaTcp(Action<MqttClientTcpConfigurationBuilder>)

    Specifies the TCP connection settings using only a builder action to configure all TCP options.

    Declaration
    public MqttClientConfigurationBuilder ConnectViaTcp(Action<MqttClientTcpConfigurationBuilder> tcpConfigurationBuilderAction)
    Parameters
    Type Name Description
    Action<MqttClientTcpConfigurationBuilder> tcpConfigurationBuilderAction

    The action that configures the MqttClientTcpConfigurationBuilder.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    ConnectViaTcp(EndPoint, Action<MqttClientTcpConfigurationBuilder>?)

    Specifies the TCP connection settings using an EndPoint and an optional builder to configure additional TCP options.

    Declaration
    public MqttClientConfigurationBuilder ConnectViaTcp(EndPoint endpoint, Action<MqttClientTcpConfigurationBuilder>? tcpConfigurationBuilderAction = null)
    Parameters
    Type Name Description
    EndPoint endpoint

    The remote endpoint.

    Action<MqttClientTcpConfigurationBuilder> tcpConfigurationBuilderAction

    An optional action that configures the MqttClientTcpConfigurationBuilder.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    ConnectViaTcp(string, Action<MqttClientTcpConfigurationBuilder>?)

    Specifies the TCP connection settings using the host name and an optional builder to configure additional TCP options.

    Declaration
    public MqttClientConfigurationBuilder ConnectViaTcp(string host, Action<MqttClientTcpConfigurationBuilder>? tcpConfigurationBuilderAction = null)
    Parameters
    Type Name Description
    string host

    The server host name or IP address.

    Action<MqttClientTcpConfigurationBuilder> tcpConfigurationBuilderAction

    An optional action that configures the MqttClientTcpConfigurationBuilder.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    ConnectViaTcp(string, int, Action<MqttClientTcpConfigurationBuilder>?)

    Specifies the TCP connection settings using the host name, port and an optional builder to configure additional TCP options.

    Declaration
    public MqttClientConfigurationBuilder ConnectViaTcp(string host, int port, Action<MqttClientTcpConfigurationBuilder>? tcpConfigurationBuilderAction = null)
    Parameters
    Type Name Description
    string host

    The server host name or IP address.

    int port

    The server port.

    Action<MqttClientTcpConfigurationBuilder> tcpConfigurationBuilderAction

    An optional action that configures the MqttClientTcpConfigurationBuilder.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    ConnectViaWebSocket(Action<MqttClientWebSocketConfigurationBuilder>)

    Specifies the WebSocket connection settings.

    Declaration
    public MqttClientConfigurationBuilder ConnectViaWebSocket(Action<MqttClientWebSocketConfigurationBuilder> webSocketConfigurationBuilderAction)
    Parameters
    Type Name Description
    Action<MqttClientWebSocketConfigurationBuilder> webSocketConfigurationBuilderAction

    The action that configures the MqttClientWebSocketConfigurationBuilder.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    ConnectViaWebSocket(string, Action<MqttClientWebSocketConfigurationBuilder>?)

    Specifies the WebSocket connection settings.

    Declaration
    public MqttClientConfigurationBuilder ConnectViaWebSocket(string uri, Action<MqttClientWebSocketConfigurationBuilder>? webSocketConfigurationBuilderAction = null)
    Parameters
    Type Name Description
    string uri

    The server URI.

    Action<MqttClientWebSocketConfigurationBuilder> webSocketConfigurationBuilderAction

    The action that configures the MqttClientWebSocketConfigurationBuilder.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    Consume(Action<MqttConsumerEndpointConfigurationBuilder<object>>)

    Adds a consumer endpoint, which is a topic or a group of topics that share the same configuration (deserializer, error policies, etc.).

    Declaration
    public MqttClientConfigurationBuilder Consume(Action<MqttConsumerEndpointConfigurationBuilder<object>> configurationBuilderAction)
    Parameters
    Type Name Description
    Action<MqttConsumerEndpointConfigurationBuilder<object>> configurationBuilderAction

    An Action that takes the MqttClientConfigurationBuilder and configures it.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    Consume(string?, Action<MqttConsumerEndpointConfigurationBuilder<object>>)

    Adds a consumer endpoint, which is a topic or a group of topics that share the same configuration (deserializer, error policies, etc.).

    Declaration
    public MqttClientConfigurationBuilder Consume(string? name, Action<MqttConsumerEndpointConfigurationBuilder<object>> configurationBuilderAction)
    Parameters
    Type Name Description
    string name

    The name is used to guarantee that a duplicated configuration is discarded and is also displayed in the logs. By default, the name will be generated concatenating the topic name(s).

    Action<MqttConsumerEndpointConfigurationBuilder<object>> configurationBuilderAction

    An Action that takes the MqttClientConfigurationBuilder and configures it.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    Consume<TMessage>(Action<MqttConsumerEndpointConfigurationBuilder<TMessage>>)

    Adds a consumer endpoint, which is a topic or a group of topics that share the same configuration (deserializer, error policies, etc.).

    Declaration
    public MqttClientConfigurationBuilder Consume<TMessage>(Action<MqttConsumerEndpointConfigurationBuilder<TMessage>> configurationBuilderAction)
    Parameters
    Type Name Description
    Action<MqttConsumerEndpointConfigurationBuilder<TMessage>> configurationBuilderAction

    An Action that takes the MqttClientConfigurationBuilder and configures it.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    Type Parameters
    Name Description
    TMessage

    The type (or base type) of the messages being consumed. This is used to setup the deserializer and will determine the type of the message parameter in the nested configuration functions.

    Consume<TMessage>(string?, Action<MqttConsumerEndpointConfigurationBuilder<TMessage>>)

    Adds a consumer endpoint, which is a topic or a group of topics that share the same configuration (deserializer, error policies, etc.).

    Declaration
    public MqttClientConfigurationBuilder Consume<TMessage>(string? name, Action<MqttConsumerEndpointConfigurationBuilder<TMessage>> configurationBuilderAction)
    Parameters
    Type Name Description
    string name

    The name is used to guarantee that a duplicated configuration is discarded and is also displayed in the logs. By default, the name will be generated concatenating the topic name(s).

    Action<MqttConsumerEndpointConfigurationBuilder<TMessage>> configurationBuilderAction

    An Action that takes the MqttClientConfigurationBuilder and configures it.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    Type Parameters
    Name Description
    TMessage

    The type (or base type) of the messages being consumed. This is used to setup the deserializer and will determine the type of the message parameter in the nested configuration functions.

    DisableKeepAlive()

    Disables the keep alive mechanism. No ping packet will be sent.

    Declaration
    public MqttClientConfigurationBuilder DisableKeepAlive()
    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    DisablePacketFragmentation()

    Disables packet fragmentation. This is necessary when the broker does not support it.

    Declaration
    public MqttClientConfigurationBuilder DisablePacketFragmentation()
    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    DisableParallelProcessing()

    Disables parallel messages processing, setting the max degree of parallelism to 1 (default).

    Declaration
    public MqttClientConfigurationBuilder DisableParallelProcessing()
    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    DisableProblemInformation()

    Specifies that the reason string or user properties can be sent with CONNACK or DISCONNECT packets only.

    Declaration
    public MqttClientConfigurationBuilder DisableProblemInformation()
    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    DisableResponseInformation()

    Specifies that the server should not return the response information in the CONNACK packet. This is usually the default.

    Declaration
    public MqttClientConfigurationBuilder DisableResponseInformation()
    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    DisableTls()

    Disables TLS. The network traffic will not be encrypted.

    Declaration
    public MqttClientConfigurationBuilder DisableTls()
    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    DisableTryPrivate()

    Disables the TryPrivate.

    Declaration
    public MqttClientConfigurationBuilder DisableTryPrivate()
    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    EnableParallelProcessing(int)

    Enables parallel processing and sets the maximum number of incoming messages that can be processed concurrently.

    Declaration
    public MqttClientConfigurationBuilder EnableParallelProcessing(int maxDegreeOfParallelism)
    Parameters
    Type Name Description
    int maxDegreeOfParallelism

    The maximum number of incoming messages that can be processed concurrently.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    EnableTls(Action<MqttClientTlsConfigurationBuilder>?)

    Specifies that TLS has to be used to encrypt the network traffic.

    Declaration
    public MqttClientConfigurationBuilder EnableTls(Action<MqttClientTlsConfigurationBuilder>? tlsConfigurationBuilderAction = null)
    Parameters
    Type Name Description
    Action<MqttClientTlsConfigurationBuilder> tlsConfigurationBuilderAction

    The action that configures the MqttClientTlsConfigurationBuilder.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    EnableTryPrivate()

    Specifies that the bridge must attempt to indicate to the remote broker that it is a bridge and not an ordinary client. If successful, this means that the loop detection will be more effective and that the retained messages will be propagated correctly. Not all brokers support this feature, so it may be necessary to disable it if your bridge does not connect properly.

    Declaration
    public MqttClientConfigurationBuilder EnableTryPrivate()
    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    LimitBackpressure(int)

    Sets the maximum number of messages to be consumed and enqueued waiting to be processed. The limit will be applied per partition when processing the partitions independently (default). The default limit is 2.

    Declaration
    public MqttClientConfigurationBuilder LimitBackpressure(int backpressureLimit)
    Parameters
    Type Name Description
    int backpressureLimit

    The maximum number of messages to be enqueued.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    LimitPacketSize(long)

    Sets the maximum packet size in byte the client will process. The default is no limit.

    Declaration
    public MqttClientConfigurationBuilder LimitPacketSize(long maximumPacketSize)
    Parameters
    Type Name Description
    long maximumPacketSize

    The maximum packet size.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    LimitTopicAlias(int)

    Sets the maximum number of topic aliases the server can send in the PUBLISH packet. The default is 0, meaning that no alias can be sent.

    Declaration
    public MqttClientConfigurationBuilder LimitTopicAlias(int topicAliasMaximum)
    Parameters
    Type Name Description
    int topicAliasMaximum

    The maximum number of topic aliases.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    LimitUnacknowledgedPublications(int)

    Sets the maximum number of QoS 1 and QoS 2 publications that can be received and processed concurrently. The default value is null, that means 65'535.

    Declaration
    public MqttClientConfigurationBuilder LimitUnacknowledgedPublications(int receiveMaximum)
    Parameters
    Type Name Description
    int receiveMaximum

    The maximum number of concurrent publications.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    Remarks

    There is no mechanism to limit the QoS 0 publications that the Server might try to send.

    Produce(Action<MqttProducerEndpointConfigurationBuilder<object>>)

    Adds a producer endpoint, which is a topic and its related configuration (serializer, etc.).

    Declaration
    public MqttClientConfigurationBuilder Produce(Action<MqttProducerEndpointConfigurationBuilder<object>> configurationBuilderAction)
    Parameters
    Type Name Description
    Action<MqttProducerEndpointConfigurationBuilder<object>> configurationBuilderAction

    An Action that takes the MqttClientConfigurationBuilder and configures it.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    Produce(string?, Action<MqttProducerEndpointConfigurationBuilder<object>>)

    Adds a producer endpoint, which is a topic and its related configuration (serializer, etc.).

    Declaration
    public MqttClientConfigurationBuilder Produce(string? name, Action<MqttProducerEndpointConfigurationBuilder<object>> configurationBuilderAction)
    Parameters
    Type Name Description
    string name

    The name is used to guarantee that a duplicated configuration is discarded and is also displayed in the logs. By default, the name will be generated concatenating the topic name and the message type.

    Action<MqttProducerEndpointConfigurationBuilder<object>> configurationBuilderAction

    An Action that takes the MqttClientConfigurationBuilder and configures it.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    Produce<TMessage>(Action<MqttProducerEndpointConfigurationBuilder<TMessage>>)

    Adds a producer endpoint, which is a topic and its related configuration (serializer, etc.).

    Declaration
    public MqttClientConfigurationBuilder Produce<TMessage>(Action<MqttProducerEndpointConfigurationBuilder<TMessage>> configurationBuilderAction) where TMessage : class
    Parameters
    Type Name Description
    Action<MqttProducerEndpointConfigurationBuilder<TMessage>> configurationBuilderAction

    An Action that takes the MqttClientConfigurationBuilder and configures it.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    Type Parameters
    Name Description
    TMessage

    The type (or base type) of the messages being produced. This is used to setup the serializer and will determine the type of the message parameter in the nested configuration functions.

    Produce<TMessage>(string?, Action<MqttProducerEndpointConfigurationBuilder<TMessage>>)

    Adds a producer endpoint, which is a topic and its related configuration (serializer, etc.).

    Declaration
    public MqttClientConfigurationBuilder Produce<TMessage>(string? name, Action<MqttProducerEndpointConfigurationBuilder<TMessage>> configurationBuilderAction) where TMessage : class
    Parameters
    Type Name Description
    string name

    The name is used to guarantee that a duplicated configuration is discarded and is also displayed in the logs. By default the name will be generated concatenating the topic name and the message type.

    Action<MqttProducerEndpointConfigurationBuilder<TMessage>> configurationBuilderAction

    An Action that takes the MqttClientConfigurationBuilder and configures it.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    Type Parameters
    Name Description
    TMessage

    The type (or base type) of the messages being produced. This is used to setup the serializer and will determine the type of the message parameter in the nested configuration functions.

    RequestCleanSession()

    Specifies that a clean non-persistent session has to be created for this client. This is the default, use RequestPersistentSession(TimeSpan) to switch to a persistent session.

    Declaration
    public MqttClientConfigurationBuilder RequestCleanSession()
    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    Remarks

    Clean session in MQTT versions below 5.0 is the same as clean start in MQTT 5.0. RequestCleanSession() and RequestCleanStart() are the same.

    RequestCleanStart()

    Specifies that a clean non-persistent session has to be created for this client. This is the default, use RequestPersistentSession(TimeSpan) to switch to a persistent session.

    Declaration
    public MqttClientConfigurationBuilder RequestCleanStart()
    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    Remarks

    Clean session in MQTT versions below 5.0 is the same as clean start in MQTT 5.0. RequestCleanSession() and RequestCleanStart() are the same.

    RequestPersistentSession(TimeSpan)

    Specifies that a persistent session has to be created for this client.

    Declaration
    public MqttClientConfigurationBuilder RequestPersistentSession(TimeSpan sessionExpiryInterval = default)
    Parameters
    Type Name Description
    TimeSpan sessionExpiryInterval

    The TimeSpan representing the session expiry interval.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    RequestProblemInformation()

    Specifies that the reason string or user properties can be sent with any packet. This is usually the default.

    Declaration
    public MqttClientConfigurationBuilder RequestProblemInformation()
    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    RequestResponseInformation()

    Specifies that the server should return the response information in the CONNACK packet.

    Declaration
    public MqttClientConfigurationBuilder RequestResponseInformation()
    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    SendKeepAlive(TimeSpan)

    Sets the maximum period that can elapse without a packet being sent to the message broker. When this period is elapsed a ping packet will be sent to keep the connection alive. The default is 15 seconds.

    Declaration
    public MqttClientConfigurationBuilder SendKeepAlive(TimeSpan interval)
    Parameters
    Type Name Description
    TimeSpan interval

    The maximum period that can elapse without a packet being sent.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    SendLastWillMessage<TLwtMessage>(Action<MqttLastWillMessageConfigurationBuilder<TLwtMessage>>)

    Specifies the last will and testament (LWT) message to be sent when the client disconnects ungracefully.

    Declaration
    public MqttClientConfigurationBuilder SendLastWillMessage<TLwtMessage>(Action<MqttLastWillMessageConfigurationBuilder<TLwtMessage>> lastWillBuilderAction)
    Parameters
    Type Name Description
    Action<MqttLastWillMessageConfigurationBuilder<TLwtMessage>> lastWillBuilderAction

    An Action<T> that takes the MqttLastWillMessageConfigurationBuilder<TMessage> and configures it.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    Type Parameters
    Name Description
    TLwtMessage

    The LWT message type.

    UseEnhancedAuthenticationHandler(IMqttEnhancedAuthenticationHandler)

    Sets the handler to be used to handle the authentication.

    Declaration
    public MqttClientConfigurationBuilder UseEnhancedAuthenticationHandler(IMqttEnhancedAuthenticationHandler handler)
    Parameters
    Type Name Description
    IMqttEnhancedAuthenticationHandler handler

    The MQTTnet.IMqttEnhancedAuthenticationHandler instance to be used.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    UseEnhancedAuthenticationHandler(Type)

    Sets the handler to be used to handle the authentication.

    Declaration
    public MqttClientConfigurationBuilder UseEnhancedAuthenticationHandler(Type handlerType)
    Parameters
    Type Name Description
    Type handlerType

    The type of the MQTTnet.IMqttEnhancedAuthenticationHandler to be used. The instance will be resolved via the IServiceProvider.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    UseEnhancedAuthenticationHandler<THandler>()

    Sets the handler to be used to handle the authentication.

    Declaration
    public MqttClientConfigurationBuilder UseEnhancedAuthenticationHandler<THandler>() where THandler : IMqttEnhancedAuthenticationHandler
    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    Type Parameters
    Name Description
    THandler

    The type of the MQTTnet.IMqttEnhancedAuthenticationHandler to be used. The instance will be resolved via the IServiceProvider.

    UseProtocolVersion(MqttProtocolVersion)

    Specifies the MQTT protocol version. The default is MQTTnet.Formatter.MqttProtocolVersion.V500.

    Declaration
    public MqttClientConfigurationBuilder UseProtocolVersion(MqttProtocolVersion value)
    Parameters
    Type Name Description
    MqttProtocolVersion value

    The MQTTnet.Formatter.MqttProtocolVersion.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    WithAcknowledgmentTimeout(TimeSpan)

    Sets the maximum time to wait for the acknowledgment operation to complete. The default is 30 seconds.

    Declaration
    public MqttClientConfigurationBuilder WithAcknowledgmentTimeout(TimeSpan timeout)
    Parameters
    Type Name Description
    TimeSpan timeout

    The maximum time to wait for the acknowledgment operation to complete.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    WithClientId(string)

    Sets the client identifier. The default is Guid.NewGuid().ToString().

    Declaration
    public MqttClientConfigurationBuilder WithClientId(string value)
    Parameters
    Type Name Description
    string value

    The client identifier.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    WithCredentials(IMqttClientCredentialsProvider)

    Sets the credential to be used to authenticate with the message broker.

    Declaration
    public MqttClientConfigurationBuilder WithCredentials(IMqttClientCredentialsProvider credentialsProvider)
    Parameters
    Type Name Description
    IMqttClientCredentialsProvider credentialsProvider

    The MQTTnet.IMqttClientCredentialsProvider.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    WithCredentials(string, byte[]?)

    Sets the credential to be used to authenticate with the message broker.

    Declaration
    public MqttClientConfigurationBuilder WithCredentials(string username, byte[]? password = null)
    Parameters
    Type Name Description
    string username

    The username.

    byte[] password

    The user password.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    WithCredentials(string, string?)

    Sets the credential to be used to authenticate with the message broker.

    Declaration
    public MqttClientConfigurationBuilder WithCredentials(string username, string? password = null)
    Parameters
    Type Name Description
    string username

    The username.

    string password

    The user password.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    WithEnhancedAuthentication(string?, byte[]?)

    Specifies the authentication method to be used and the associated data.

    Declaration
    public MqttClientConfigurationBuilder WithEnhancedAuthentication(string? method, byte[]? data)
    Parameters
    Type Name Description
    string method

    The authentication method.

    byte[] data

    The authentication data.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    WithSessionExpiration(TimeSpan)

    Sets the session expiry interval. When set to 0 the session will expire when the connection is closed, while MaxValue indicates that the session will never expire. The default is 0.

    Declaration
    public MqttClientConfigurationBuilder WithSessionExpiration(TimeSpan sessionExpiryInterval)
    Parameters
    Type Name Description
    TimeSpan sessionExpiryInterval

    The TimeSpan representing the session expiry interval.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    WithTimeout(TimeSpan)

    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.

    Declaration
    public MqttClientConfigurationBuilder WithTimeout(TimeSpan value)
    Parameters
    Type Name Description
    TimeSpan value

    The TimeSpan representing the timeout.

    Returns
    Type Description
    MqttClientConfigurationBuilder

    The MqttClientConfigurationBuilder so that additional calls can be chained.

    GitHub E-Mail
    ↑ Back to top © 2026 Sergio Aquilini