Class MqttClientsConfigurationBuilder
- Namespace
- Silverback.Messaging.Configuration.Mqtt
- Assembly
- Silverback.Integration.MQTT.dll
Configures the MQTT clients building the MqttClientConfiguration.
public sealed class MqttClientsConfigurationBuilder
- Inheritance
-
MqttClientsConfigurationBuilder
- Inherited Members
Constructors
MqttClientsConfigurationBuilder()
public MqttClientsConfigurationBuilder()
Methods
AddClient(Action<MqttClientConfigurationBuilder>)
Adds an MQTT client.
public MqttClientsConfigurationBuilder AddClient(Action<MqttClientConfigurationBuilder> configurationBuilderAction)
Parameters
configurationBuilderActionAction<MqttClientConfigurationBuilder>An Action that takes the MqttClientConfigurationBuilder and configures it.
Returns
- 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.
public MqttClientsConfigurationBuilder AddClient(string name, Action<MqttClientConfigurationBuilder> configurationBuilderAction)
Parameters
namestringThe producer name, used to merge the configuration with the existing one.
configurationBuilderActionAction<MqttClientConfigurationBuilder>An Action that takes the MqttClientConfigurationBuilder and configures it.
Returns
- 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.
public MqttClientsConfigurationBuilder AddUserProperty(string name, string? value)
Parameters
Returns
- MqttClientsConfigurationBuilder
The MqttClientsConfigurationBuilder so that additional calls can be chained.
AllowPacketFragmentation()
Allow packet fragmentation. This is the default, use DisablePacketFragmentation() to turn it off.
public MqttClientsConfigurationBuilder AllowPacketFragmentation()
Returns
- MqttClientsConfigurationBuilder
The MqttClientsConfigurationBuilder so that additional calls can be chained.
ConnectTo(string)
Specifies the URI of the MQTT server.
public MqttClientsConfigurationBuilder ConnectTo(string serverUri)
Parameters
serverUristringThe URI of the MQTT server.
Returns
- MqttClientsConfigurationBuilder
The MqttClientsConfigurationBuilder so that additional calls can be chained.
ConnectTo(Uri)
Specifies the URI of the MQTT server.
public MqttClientsConfigurationBuilder ConnectTo(Uri serverUri)
Parameters
serverUriUriThe URI of the MQTT server.
Returns
- 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.
public MqttClientsConfigurationBuilder ConnectViaTcp(Action<MqttClientTcpConfigurationBuilder> tcpConfigurationBuilderAction)
Parameters
tcpConfigurationBuilderActionAction<MqttClientTcpConfigurationBuilder>The action that configures the MqttClientTcpConfigurationBuilder.
Returns
- 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.
public MqttClientsConfigurationBuilder ConnectViaTcp(EndPoint endpoint, Action<MqttClientTcpConfigurationBuilder>? tcpConfigurationBuilderAction = null)
Parameters
endpointEndPointThe remote endpoint.
tcpConfigurationBuilderActionAction<MqttClientTcpConfigurationBuilder>An optional action that configures the MqttClientTcpConfigurationBuilder.
Returns
- 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.
public MqttClientsConfigurationBuilder ConnectViaTcp(string host, Action<MqttClientTcpConfigurationBuilder>? tcpConfigurationBuilderAction = null)
Parameters
hoststringThe server host name or IP address.
tcpConfigurationBuilderActionAction<MqttClientTcpConfigurationBuilder>An optional action that configures the MqttClientTcpConfigurationBuilder.
Returns
- 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.
public MqttClientsConfigurationBuilder ConnectViaTcp(string host, int port, Action<MqttClientTcpConfigurationBuilder>? tcpConfigurationBuilderAction = null)
Parameters
hoststringThe server host name or IP address.
portintThe server port.
tcpConfigurationBuilderActionAction<MqttClientTcpConfigurationBuilder>An optional action that configures the MqttClientTcpConfigurationBuilder.
Returns
- MqttClientsConfigurationBuilder
The MqttClientsConfigurationBuilder so that additional calls can be chained.
ConnectViaWebSocket(Action<MqttClientWebSocketConfigurationBuilder>)
Specifies the WebSocket connection settings.
public MqttClientsConfigurationBuilder ConnectViaWebSocket(Action<MqttClientWebSocketConfigurationBuilder> webSocketConfigurationBuilderAction)
Parameters
webSocketConfigurationBuilderActionAction<MqttClientWebSocketConfigurationBuilder>The action that configures the MqttClientWebSocketConfigurationBuilder.
Returns
- MqttClientsConfigurationBuilder
The MqttClientsConfigurationBuilder so that additional calls can be chained.
ConnectViaWebSocket(string, Action<MqttClientWebSocketConfigurationBuilder>?)
Specifies the WebSocket connection settings.
public MqttClientsConfigurationBuilder ConnectViaWebSocket(string uri, Action<MqttClientWebSocketConfigurationBuilder>? webSocketConfigurationBuilderAction = null)
Parameters
uristringThe server URI.
webSocketConfigurationBuilderActionAction<MqttClientWebSocketConfigurationBuilder>The action that configures the MqttClientWebSocketConfigurationBuilder.
Returns
- MqttClientsConfigurationBuilder
The MqttClientsConfigurationBuilder so that additional calls can be chained.
DisableKeepAlive()
Disables the keep alive mechanism. No ping packet will be sent.
public MqttClientsConfigurationBuilder DisableKeepAlive()
Returns
- MqttClientsConfigurationBuilder
The MqttClientsConfigurationBuilder so that additional calls can be chained.
DisablePacketFragmentation()
Disables packet fragmentation. This is necessary when the broker does not support it.
public MqttClientsConfigurationBuilder DisablePacketFragmentation()
Returns
- MqttClientsConfigurationBuilder
The MqttClientsConfigurationBuilder so that additional calls can be chained.
DisableParallelProcessing()
Disables parallel messages processing, setting the max degree of parallelism to 1 (default).
public MqttClientsConfigurationBuilder DisableParallelProcessing()
Returns
- 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.
public MqttClientsConfigurationBuilder DisableProblemInformation()
Returns
- 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.
public MqttClientsConfigurationBuilder DisableResponseInformation()
Returns
- MqttClientsConfigurationBuilder
The MqttClientsConfigurationBuilder so that additional calls can be chained.
DisableTls()
Disables TLS. The network traffic will not be encrypted.
public MqttClientsConfigurationBuilder DisableTls()
Returns
- MqttClientsConfigurationBuilder
The MqttClientsConfigurationBuilder so that additional calls can be chained.
DisableTryPrivate()
Disables the TryPrivate.
public MqttClientsConfigurationBuilder DisableTryPrivate()
Returns
- 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.
public MqttClientsConfigurationBuilder EnableParallelProcessing(int maxDegreeOfParallelism)
Parameters
maxDegreeOfParallelismintThe maximum number of incoming message that can be processed concurrently.
Returns
- 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.
public MqttClientsConfigurationBuilder EnableTls(Action<MqttClientTlsConfigurationBuilder>? tlsConfigurationBuilderAction = null)
Parameters
tlsConfigurationBuilderActionAction<MqttClientTlsConfigurationBuilder>The action that configures the MqttClientTlsConfigurationBuilder.
Returns
- 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.
public MqttClientsConfigurationBuilder EnableTryPrivate()
Returns
- 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.
public MqttClientsConfigurationBuilder LimitBackpressure(int backpressureLimit)
Parameters
backpressureLimitintThe maximum number of messages to be enqueued.
Returns
- 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.
public MqttClientsConfigurationBuilder LimitPacketSize(long maximumPacketSize)
Parameters
maximumPacketSizelongThe maximum packet size.
Returns
- 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.
public MqttClientsConfigurationBuilder LimitTopicAlias(int topicAliasMaximum)
Parameters
topicAliasMaximumintThe maximum number of topic aliases.
Returns
- 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.
public MqttClientsConfigurationBuilder LimitUnacknowledgedPublications(int receiveMaximum)
Parameters
receiveMaximumintThe maximum number of concurrent publications.
Returns
- 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.
public MqttClientsConfigurationBuilder RequestCleanSession()
Returns
- 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.
public MqttClientsConfigurationBuilder RequestCleanStart()
Returns
- 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.
public MqttClientsConfigurationBuilder RequestPersistentSession()
Returns
- 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.
public MqttClientsConfigurationBuilder RequestProblemInformation()
Returns
- MqttClientsConfigurationBuilder
The MqttClientsConfigurationBuilder so that additional calls can be chained.
RequestResponseInformation()
Specifies that the server should return the response information in the CONNACK packet.
public MqttClientsConfigurationBuilder RequestResponseInformation()
Returns
- 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.
public MqttClientsConfigurationBuilder SendKeepAlive(TimeSpan interval)
Parameters
intervalTimeSpanThe maximum period that can elapse without a packet being sent.
Returns
- 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.
public MqttClientsConfigurationBuilder SendLastWillMessage<TLwtMessage>(Action<MqttLastWillMessageConfigurationBuilder<TLwtMessage>> lastWillBuilderAction)
Parameters
lastWillBuilderActionAction<MqttLastWillMessageConfigurationBuilder<TLwtMessage>>An Action<T> that takes the MqttLastWillMessageConfigurationBuilder<TMessage> and configures it.
Returns
- MqttClientsConfigurationBuilder
The MqttClientsConfigurationBuilder so that additional calls can be chained.
Type Parameters
TLwtMessageThe LWT message type.
UseEnhancedAuthenticationHandler(IMqttEnhancedAuthenticationHandler)
Sets the handler to be used to handle the authentication.
public MqttClientsConfigurationBuilder UseEnhancedAuthenticationHandler(IMqttEnhancedAuthenticationHandler handler)
Parameters
handlerIMqttEnhancedAuthenticationHandlerThe MQTTnet.IMqttEnhancedAuthenticationHandler instance to be used.
Returns
- MqttClientsConfigurationBuilder
The MqttClientsConfigurationBuilder so that additional calls can be chained.
UseEnhancedAuthenticationHandler(Type)
Sets the handler to be used to handle the authentication.
public MqttClientsConfigurationBuilder UseEnhancedAuthenticationHandler(Type handlerType)
Parameters
handlerTypeTypeThe type of the MQTTnet.IMqttEnhancedAuthenticationHandler to be used. The instance will be resolved via the IServiceProvider.
Returns
- MqttClientsConfigurationBuilder
The MqttClientsConfigurationBuilder so that additional calls can be chained.
UseEnhancedAuthenticationHandler<THandler>()
Sets the handler to be used to handle the authentication.
public MqttClientsConfigurationBuilder UseEnhancedAuthenticationHandler<THandler>() where THandler : IMqttEnhancedAuthenticationHandler
Returns
- MqttClientsConfigurationBuilder
The MqttClientsConfigurationBuilder so that additional calls can be chained.
Type Parameters
THandlerThe 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.
public MqttClientsConfigurationBuilder UseProtocolVersion(MqttProtocolVersion value)
Parameters
valueMqttProtocolVersionThe MQTTnet.Formatter.MqttProtocolVersion.
Returns
- 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.
public MqttClientsConfigurationBuilder WithAcknowledgmentTimeout(TimeSpan timeout)
Parameters
timeoutTimeSpanThe maximum time to wait for the acknowledgment operation to complete.
Returns
- MqttClientsConfigurationBuilder
The MqttClientsConfigurationBuilder so that additional calls can be chained.
WithCredentials(IMqttClientCredentialsProvider)
Sets the credential to be used to authenticate with the message broker.
public MqttClientsConfigurationBuilder WithCredentials(IMqttClientCredentialsProvider credentialsProvider)
Parameters
credentialsProviderIMqttClientCredentialsProviderThe MQTTnet.IMqttClientCredentialsProvider.
Returns
- 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.
public MqttClientsConfigurationBuilder WithCredentials(string username, byte[]? password = null)
Parameters
Returns
- 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.
public MqttClientsConfigurationBuilder WithCredentials(string username, string? password = null)
Parameters
Returns
- MqttClientsConfigurationBuilder
The MqttClientsConfigurationBuilder so that additional calls can be chained.
WithEnhancedAuthentication(string?, byte[]?)
Specifies the authentication method to be used and the associated data.
public MqttClientsConfigurationBuilder WithEnhancedAuthentication(string? method, byte[]? data)
Parameters
Returns
- 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.
public MqttClientsConfigurationBuilder WithSessionExpiration(TimeSpan sessionExpiryInterval)
Parameters
Returns
- 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.
public MqttClientsConfigurationBuilder WithTimeout(TimeSpan value)
Parameters
Returns
- MqttClientsConfigurationBuilder
The MqttClientsConfigurationBuilder so that additional calls can be chained.