Skip to content

Commit 407e3e6

Browse files
committed
allow direct setting of connect properties to builder
1 parent 335df21 commit 407e3e6

File tree

1 file changed

+200
-0
lines changed

1 file changed

+200
-0
lines changed

sdk/src/main/java/software/amazon/awssdk/iot/AwsIotMqtt5ClientBuilder.java

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@
3333
import software.amazon.awssdk.crt.mqtt5.Mqtt5WebsocketHandshakeTransformArgs;
3434
import software.amazon.awssdk.crt.mqtt5.Mqtt5ClientOptions.Mqtt5ClientOptionsBuilder;
3535
import software.amazon.awssdk.crt.mqtt5.packets.ConnectPacket.ConnectPacketBuilder;
36+
import software.amazon.awssdk.crt.mqtt5.packets.PublishPacket;
3637
import software.amazon.awssdk.crt.mqtt5.TopicAliasingOptions;
3738
import software.amazon.awssdk.crt.utils.PackageInfo;
39+
import software.amazon.awssdk.crt.mqtt5.packets.UserProperty;
3840

3941
/**
4042
* Builders for making MQTT5 clients with different connection methods for AWS IoT Core.
@@ -664,6 +666,204 @@ public AwsIotMqtt5ClientBuilder withTlsCipherPreference(TlsCipherPreference tlsC
664666
return this;
665667
}
666668

669+
/**
670+
* Sets the maximum time interval, in seconds, that is permitted to elapse between the point at which the client
671+
* finishes transmitting one MQTT packet and the point it starts sending the next. The client will use
672+
* PINGREQ packets to maintain this property.
673+
*
674+
* If the responding ConnAckPacket contains a keep alive property value, then that is the negotiated keep alive value.
675+
* Otherwise, the keep alive sent by the client is the negotiated value.
676+
*
677+
* See <a href="https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901045">MQTT5 Keep Alive</a>
678+
*
679+
* NOTE: The keepAliveIntervalSeconds HAS to be larger than the pingTimeoutMs time set in the Mqtt5ClientOptions.
680+
*
681+
* @param keepAliveInteralSeconds the maximum time interval, in seconds, that is permitted to elapse between the point
682+
* at which the client finishes transmitting one MQTT packet and the point it starts sending the next.
683+
* @return The ConnectPacketBuilder after setting the keep alive interval.
684+
*/
685+
public AwsIotMqtt5ClientBuilder withKeepAliveIntervalSeconds(Long keepAliveInteralSeconds)
686+
{
687+
this.configConnect.withKeepAliveIntervalSeconds(keepAliveInteralSeconds);
688+
return this;
689+
}
690+
691+
/**
692+
* Sets the unique string identifying the client to the server. Used to restore session state between connections.
693+
*
694+
* If left empty, the broker will auto-assign a unique client id. When reconnecting, the Mqtt5Client will
695+
* always use the auto-assigned client id.
696+
*
697+
* See <a href="https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901059">MQTT5 Client Identifier</a>
698+
*
699+
* @param clientId A unique string identifying the client to the server.
700+
* @return The ConnectPacketBuilder after setting the client ID.
701+
*/
702+
public AwsIotMqtt5ClientBuilder withClientId(String clientId)
703+
{
704+
this.configConnect.withClientId(clientId);
705+
return this;
706+
}
707+
708+
/**
709+
* Sets the string value that the server may use for client authentication and authorization.
710+
*
711+
* See <a href="https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901071">MQTT5 User Name</a>
712+
*
713+
* @param username The string value that the server may use for client authentication and authorization.
714+
* @return The ConnectPacketBuilder after setting the username.
715+
*/
716+
public AwsIotMqtt5ClientBuilder withUsername(String username)
717+
{
718+
this.configConnect.withUsername(username)
719+
return this;
720+
}
721+
722+
/**
723+
* Sets the opaque binary data that the server may use for client authentication and authorization.
724+
*
725+
* See <a href="https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901072">MQTT5 Password</a>
726+
*
727+
* @param password Opaque binary data that the server may use for client authentication and authorization.
728+
* @return The ConnectPacketBuilder after setting the password.
729+
*/
730+
public AwsIotMqtt5ClientBuilder withPassword(byte[] password)
731+
{
732+
this.configConnect.withPassword(password);
733+
return this;
734+
}
735+
736+
/**
737+
* Sets the time interval, in seconds, that the client requests the server to persist this connection's MQTT session state
738+
* for. Has no meaning if the client has not been configured to rejoin sessions. Must be non-zero in order to
739+
* successfully rejoin a session.
740+
*
741+
* If the responding ConnAckPacket contains a session expiry property value, then that is the negotiated session expiry
742+
* value. Otherwise, the session expiry sent by the client is the negotiated value.
743+
*
744+
* See <a href="https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901048">MQTT5 Session Expiry Interval</a>
745+
*
746+
* @param sessionExpiryIntervalSeconds A time interval, in seconds, that the client requests the server to persist this
747+
* connection's MQTT session state for.
748+
* @return The ConnectPacketBuilder after setting the session expiry interval.
749+
*/
750+
751+
public AwsIotMqtt5ClientBuilder withSessionExpiryIntervalSeconds(Long sessionExpiryIntervalSeconds)
752+
{
753+
this.configConnect.withSessionExpiryIntervalSeconds(sessionExpiryIntervalSeconds);
754+
return this;
755+
}
756+
757+
/**
758+
* Sets whether requests that the server send response information in the subsequent ConnAckPacket. This response
759+
* information may be used to set up request-response implementations over MQTT, but doing so is outside
760+
* the scope of the MQTT5 spec and client.
761+
*
762+
* See <a href="https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901052">MQTT5 Request Response Information</a>
763+
*
764+
* @param requestResponseInformation If true, requests that the server send response information in the subsequent ConnAckPacket.
765+
* @return The ConnectPacketBuilder after setting the request response information.
766+
*/
767+
public AwsIotMqtt5ClientBuilder withRequestResponseInformation(Boolean requestResponseInformation)
768+
{
769+
this.configConnect.withRequestResponseInformation(requestResponseInformation);
770+
return this;
771+
}
772+
773+
/**
774+
* Sets whether requests that the server send additional diagnostic information (via response string or
775+
* user properties) in DisconnectPacket or ConnAckPacket from the server.
776+
*
777+
* See <a href="https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901053">MQTT5 Request Problem Information</a>
778+
*
779+
* @param requestProblemInformation If true, requests that the server send additional diagnostic information
780+
* (via response string or user properties) in DisconnectPacket or ConnAckPacket from the server.
781+
* @return The ConnectPacketBuilder after setting the request problem information.
782+
*/
783+
public AwsIotMqtt5ClientBuilder withRequestProblemInformation(Boolean requestProblemInformation)
784+
{
785+
this.configConnect.withRequestProblemInformation(requestProblemInformation);
786+
return this;
787+
}
788+
789+
/**
790+
* Sets the maximum number of in-flight QoS 1 and 2 messages the client is willing to handle. If
791+
* omitted or null, then no limit is requested.
792+
*
793+
* See <a href="https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901049">MQTT5 Receive Maximum</a>
794+
*
795+
* @param receiveMaximum The maximum number of in-flight QoS 1 and 2 messages the client is willing to handle.
796+
* @return The ConnectPacketBuilder after setting the receive maximum.
797+
*/
798+
public AwsIotMqtt5ClientBuilder withReceiveMaximum(Long receiveMaximum)
799+
{
800+
this.configConnect.withReceiveMaximum(receiveMaximum);
801+
return this;
802+
}
803+
804+
/**
805+
* Sets the maximum packet size the client is willing to handle. If
806+
* omitted or null, then no limit beyond the natural limits of MQTT packet size is requested.
807+
*
808+
* See <a href="https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901050">MQTT5 Maximum Packet Size</a>
809+
*
810+
* @param maximumPacketSizeBytes The maximum packet size the client is willing to handle
811+
* @return The ConnectPacketBuilder after setting the maximum packet size.
812+
*/
813+
public AwsIotMqtt5ClientBuilder withMaximumPacketSizeBytes(Long maximumPacketSizeBytes)
814+
{
815+
this.configConnect.withMaximumPacketSizeBytes(maximumPacketSizeBytes);
816+
return this;
817+
}
818+
819+
/**
820+
* Sets the time interval, in seconds, that the server should wait (for a session reconnection) before sending the
821+
* will message associated with the connection's session. If omitted or null, the server will send the will when the
822+
* associated session is destroyed. If the session is destroyed before a will delay interval has elapsed, then
823+
* the will must be sent at the time of session destruction.
824+
*
825+
* See <a href="https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901062">MQTT5 Will Delay Interval</a>
826+
*
827+
* @param willDelayIntervalSeconds A time interval, in seconds, that the server should wait (for a session reconnection)
828+
* before sending the will message associated with the connection's session.
829+
* @return The ConnectPacketBuilder after setting the will message delay interval.
830+
*/
831+
public AwsIotMqtt5ClientBuilder withWillDelayIntervalSeconds(Long willDelayIntervalSeconds)
832+
{
833+
this.configConnect.withWillDelayIntervalSeconds(willDelayIntervalSeconds);
834+
return this;
835+
}
836+
837+
/**
838+
* Sets the definition of a message to be published when the connection's session is destroyed by the server or when
839+
* the will delay interval has elapsed, whichever comes first. If null, then nothing will be sent.
840+
*
841+
* See <a href="https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901040">MQTT5 Will</a>
842+
*
843+
* @param will The message to be published when the connection's session is destroyed by the server or when
844+
* the will delay interval has elapsed, whichever comes first.
845+
* @return The ConnectPacketBuilder after setting the will message.
846+
*/
847+
public AwsIotMqtt5ClientBuilder withWill(PublishPacket will)
848+
{
849+
this.configConnect.withWill(will);
850+
return this;
851+
}
852+
853+
/**
854+
* Sets the list of MQTT5 user properties included with the packet.
855+
*
856+
* See <a href="https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901054">MQTT5 User Property</a>
857+
*
858+
* @param userProperties List of MQTT5 user properties included with the packet.
859+
* @return The ConnectPacketBuilder after setting the user properties.
860+
*/
861+
public AwsIotMqtt5ClientBuilder withUserProperties(List<UserProperty> userProperties)
862+
{
863+
this.configConnect.withUserProperties(userProperties);
864+
return this;
865+
}
866+
667867
/**
668868
* Constructs an MQTT5 client object configured with the options set.
669869
* @return A MQTT5ClientOptions

0 commit comments

Comments
 (0)