Description
Functions
-
WithCleanStart()
This specifies whether the connection starts a new session or is a continuation of an existing session. When WithCleanStart
is used, both the broker and client deletes theirs previously stored session data. The client continues to use its client id.
-
WithKeepAlive(ushort seconds)
Maximum seconds that can be pass between sending two packets to the broker. If no other packets are sent, the plugin will send ping requests to check and keep the connection alive.
-
WithLastWill(LastWillBuilder lastWillBuilder)
A last will can be added to the connection. The will message will be published by the broker after the network connection is subsequently closed and either the Will Delay Interval has elapsed or the session ends, unless the will message has been deleted by the broker on receipt of a DISCONNECT packet with Reason Code NormalDisconnection
or a new network connection for the ClientID is opened before the Will Delay Interval has elapsed.
Situations in which the will message is published include, but are not limited to:
- An I/O error or network failure detected by the broker.
- The client fails to communicate within the Keep Alive time.
- The client closes the network connection without first sending a DISCONNECT packet with a Reason Code
NormalDisconnection
. -
The broker closes the network connection without first receiving a DISCONNECT packet with a Reason Code
NormalDisconnection
. -
WithClientID(string clientId)
With this call the plugin’s automatic client id generation can be overwritten. If not exists the client creates a session to store its state. If a session is available for this clientId, it loads and uses it.
WithClientID
or WithSession
are used, first time connecting to the broker the plugin generates a unique id and will use it for consecutive connections.-
WithSession(Session session)
WithClientID
or WithSession
are used, first time connecting to the broker the plugin generates a unique id and will use it for consecutive connections.-
WithUserName(string userName)
Add a user name for authentication purposes.
-
WithPassword(string password)
Add a password for authentication purposes.
-
WithUserNameAndPassword(string userName, string password)
Add both user name and password for authentication purposes.
-
WithSessionExpiryInterval(UInt32 seconds)
When the Session expires the client and broker need not process the deletion of state atomically. If the Session Expiry Interval is absent the value 0 is used. If it is set to 0, or is absent, the session ends when the network connection is closed. If the Session Expiry Interval is 0xFFFFFFFF (uint.MaxValue), the session does not expire.
WithCleanStart
and set the Session Expiry Interval to 0. It will not receive Application Messages published before it connected and has to subscribe afresh to any topics that it is interested in each time it connects.-
WithReceiveMaximum(UInt16 value)
The client uses this value to limit the number of QoS 1 and QoS 2 publications that it is willing to process concurrently. There is no mechanism to limit the QoS 0 publications that the broker might try to send. The value of Receive Maximum applies only to the current Network Connection. If the Receive Maximum value is absent then its value defaults to 65,535.
-
WithMaximumPacketSize(UInt32 maximumPacketSize)
The maximum packet size the client is willing to accept. If the maximum packet size is not present, no limit on the packet size is imposed beyond the limitations in the protocol as a result of the remaining length encoding and the protocol header sizes.
-
WithTopicAliasMaximum(UInt16 maximum)
This value indicates the highest value that the client will accept as a topic alias sent by the broker. The client uses this value to limit the number of topic aliases that it is willing to hold on this connection. If topic alias maximum is absent or zero, the broker will not send any topic aliases to the client.
ushort.MaxValue
(65535). To disable receiving topic aliases from the broker call it with 0.-
WithRequestResponseInformation(bool request)
When called with true
the client request the broker to return Response Information in the ServerConnectAckMessage.
-
WithRequestProblemInformation(bool request)
The client can use this function to indicate whether the ReasonString or UserProperties are sent in the case of failures.
If the value of request problem information is false
, the broker may return a ReasonString
or UserProperties
on a connect acknowledgement or disconnect packet, but must not send a ReasonString
or UserProperties
on any packet other than publish, connect acknowledgement or disconnect. If this value is true
, the broker may return a ReasonString
or UserProperties
on any packet where it is allowed.
-
WithUserProperty(string key, string value)
User Properties on the connect packet can be used to send connection related properties from the client to the broker. The meaning of these properties is not defined by this specification.
-
WithExtendedAuthenticationMethod(string method)
Set the name of the authentication method used for extended authentication.
-
WithExtendedAuthenticationData(byte[] data)
Set the binary data containing authentication data for extended authentication. The contents of this data are defined by the authentication method.
Examples
Using default values
In this example the ConnectPacketBuilderCallback
returns with the builder received as its second parameter without modifying it. In the callback a new ConnectPacketBuilder
can be created, but it’s easier just to use the one already passed in the parameter.
var options = new ConnectionOptionsBuilder()
.WithTCP("test.mosquitto.org", 1883)
.Build();
client = new MQTTClient(options);
client.BeginConnect(ConnectPacketBuilderCallback);
ConnectPacketBuilder ConnectPacketBuilderCallback(MQTTClient client, ConnectPacketBuilder builder)
{
return builder;
}
Add UserName and Password
ConnectPacketBuilder ConnectPacketBuilderCallback(MQTTClient client, ConnectPacketBuilder builder)
{
return builder.WithUserNameAndPassword("<username>", "<password>");
}