Show / Hide Table of Contents

    Class MqttClientsConfigurationBuilder

    Configures the MQTT clients building the MqttClientConfiguration.

    Inheritance
    object
    MqttClientsConfigurationBuilder
    Inherited Members
    object.GetType()
    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 sealed class MqttClientsConfigurationBuilder

    Constructors

    MqttClientsConfigurationBuilder()

    Configures the MQTT clients building the MqttClientConfiguration.

    Declaration
    public MqttClientsConfigurationBuilder()

    Methods

    AddClient(Action<MqttClientConfigurationBuilder>)

    Adds an MQTT client.

    Declaration
    public MqttClientsConfigurationBuilder AddClient(Action<MqttClientConfigurationBuilder> configurationBuilderAction)
    Parameters
    Type Name Description
    Action<MqttClientConfigurationBuilder> configurationBuilderAction

    An Action that takes the MqttClientConfigurationBuilder and configures it.

    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder so that additional calls can be chained.

    AddClient(string, Action<MqttClientConfigurationBuilder>)

    Adds an MQTT client or updates its configuration if a client with the same name already exists.

    Declaration
    public MqttClientsConfigurationBuilder AddClient(string name, Action<MqttClientConfigurationBuilder> configurationBuilderAction)
    Parameters
    Type Name Description
    string name

    The producer name, used to merge the configuration with the existing one.

    Action<MqttClientConfigurationBuilder> configurationBuilderAction

    An Action that takes the MqttClientConfigurationBuilder and configures it.

    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder so that additional calls can be chained.

    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 MqttClientsConfigurationBuilder AddUserProperty(string name, string? value)
    Parameters
    Type Name Description
    string name

    The property name.

    string value

    The property value.

    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder so that additional calls can be chained.

    AllowPacketFragmentation()

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

    Declaration
    public MqttClientsConfigurationBuilder AllowPacketFragmentation()
    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder so that additional calls can be chained.

    ConnectTo(string)

    Specifies the URI of the MQTT server.

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

    The URI of the MQTT server.

    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder so that additional calls can be chained.

    ConnectTo(Uri)

    Specifies the URI of the MQTT server.

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

    The URI of the MQTT server.

    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder 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 MqttClientsConfigurationBuilder ConnectViaTcp(Action<MqttClientTcpConfigurationBuilder> tcpConfigurationBuilderAction)
    Parameters
    Type Name Description
    Action<MqttClientTcpConfigurationBuilder> tcpConfigurationBuilderAction

    The action that configures the MqttClientTcpConfigurationBuilder.

    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder 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 MqttClientsConfigurationBuilder 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
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder 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 MqttClientsConfigurationBuilder 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
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder 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 MqttClientsConfigurationBuilder 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
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder so that additional calls can be chained.

    ConnectViaWebSocket(Action<MqttClientWebSocketConfigurationBuilder>)

    Specifies the WebSocket connection settings.

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

    The action that configures the MqttClientWebSocketConfigurationBuilder.

    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder so that additional calls can be chained.

    ConnectViaWebSocket(string, Action<MqttClientWebSocketConfigurationBuilder>?)

    Specifies the WebSocket connection settings.

    Declaration
    public MqttClientsConfigurationBuilder 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
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder so that additional calls can be chained.

    DisableKeepAlive()

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

    Declaration
    public MqttClientsConfigurationBuilder DisableKeepAlive()
    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder so that additional calls can be chained.

    DisablePacketFragmentation()

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

    Declaration
    public MqttClientsConfigurationBuilder DisablePacketFragmentation()
    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder so that additional calls can be chained.

    DisableParallelProcessing()

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

    Declaration
    public MqttClientsConfigurationBuilder DisableParallelProcessing()
    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder 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 MqttClientsConfigurationBuilder DisableProblemInformation()
    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder 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 MqttClientsConfigurationBuilder DisableResponseInformation()
    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder so that additional calls can be chained.

    DisableTls()

    Disables TLS. The network traffic will not be encrypted.

    Declaration
    public MqttClientsConfigurationBuilder DisableTls()
    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder so that additional calls can be chained.

    DisableTryPrivate()

    Disables the TryPrivate.

    Declaration
    public MqttClientsConfigurationBuilder DisableTryPrivate()
    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder so that additional calls can be chained.

    EnableParallelProcessing(int)

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

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

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

    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder so that additional calls can be chained.

    EnableTls(Action<MqttClientTlsConfigurationBuilder>?)

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

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

    The action that configures the MqttClientTlsConfigurationBuilder.

    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder 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 MqttClientsConfigurationBuilder EnableTryPrivate()
    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder 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 MqttClientsConfigurationBuilder LimitBackpressure(int backpressureLimit)
    Parameters
    Type Name Description
    int backpressureLimit

    The maximum number of messages to be enqueued.

    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder 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 MqttClientsConfigurationBuilder LimitPacketSize(long maximumPacketSize)
    Parameters
    Type Name Description
    long maximumPacketSize

    The maximum packet size.

    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder 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 MqttClientsConfigurationBuilder LimitTopicAlias(int topicAliasMaximum)
    Parameters
    Type Name Description
    int topicAliasMaximum

    The maximum number of topic aliases.

    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder 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 MqttClientsConfigurationBuilder LimitUnacknowledgedPublications(int receiveMaximum)
    Parameters
    Type Name Description
    int receiveMaximum

    The maximum number of concurrent publications.

    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder 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.

    RequestCleanSession()

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

    Declaration
    public MqttClientsConfigurationBuilder RequestCleanSession()
    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder 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() to switch to a persistent session.

    Declaration
    public MqttClientsConfigurationBuilder RequestCleanStart()
    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder 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()

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

    Declaration
    public MqttClientsConfigurationBuilder RequestPersistentSession()
    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder 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 MqttClientsConfigurationBuilder RequestProblemInformation()
    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder so that additional calls can be chained.

    RequestResponseInformation()

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

    Declaration
    public MqttClientsConfigurationBuilder RequestResponseInformation()
    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder 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 MqttClientsConfigurationBuilder SendKeepAlive(TimeSpan interval)
    Parameters
    Type Name Description
    TimeSpan interval

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

    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder 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 MqttClientsConfigurationBuilder 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
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder 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 MqttClientsConfigurationBuilder UseEnhancedAuthenticationHandler(IMqttEnhancedAuthenticationHandler handler)
    Parameters
    Type Name Description
    IMqttEnhancedAuthenticationHandler handler

    The MQTTnet.IMqttEnhancedAuthenticationHandler instance to be used.

    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder so that additional calls can be chained.

    UseEnhancedAuthenticationHandler(Type)

    Sets the handler to be used to handle the authentication.

    Declaration
    public MqttClientsConfigurationBuilder 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
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder so that additional calls can be chained.

    UseEnhancedAuthenticationHandler<THandler>()

    Sets the handler to be used to handle the authentication.

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

    The MqttClientsConfigurationBuilder 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 MqttClientsConfigurationBuilder UseProtocolVersion(MqttProtocolVersion value)
    Parameters
    Type Name Description
    MqttProtocolVersion value

    The MQTTnet.Formatter.MqttProtocolVersion.

    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder 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 MqttClientsConfigurationBuilder WithAcknowledgmentTimeout(TimeSpan timeout)
    Parameters
    Type Name Description
    TimeSpan timeout

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

    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder so that additional calls can be chained.

    WithCredentials(IMqttClientCredentialsProvider)

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

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

    The MQTTnet.IMqttClientCredentialsProvider.

    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder so that additional calls can be chained.

    WithCredentials(string, byte[]?)

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

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

    The username.

    byte[] password

    The user password.

    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder so that additional calls can be chained.

    WithCredentials(string, string?)

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

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

    The username.

    string password

    The user password.

    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder so that additional calls can be chained.

    WithEnhancedAuthentication(string?, byte[]?)

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

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

    The authentication method.

    byte[] data

    The authentication data.

    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder 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 MqttClientsConfigurationBuilder WithSessionExpiration(TimeSpan sessionExpiryInterval)
    Parameters
    Type Name Description
    TimeSpan sessionExpiryInterval

    The TimeSpan representing the session expiry interval.

    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder 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 MqttClientsConfigurationBuilder WithTimeout(TimeSpan value)
    Parameters
    Type Name Description
    TimeSpan value

    The TimeSpan representing the timeout.

    Returns
    Type Description
    MqttClientsConfigurationBuilder

    The MqttClientsConfigurationBuilder so that additional calls can be chained.

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