Skip to content

Commit 1752650

Browse files
authored
Allow direct setting of connect properties to builder (#663)
1 parent 335df21 commit 1752650

File tree

1 file changed

+172
-0
lines changed

1 file changed

+172
-0
lines changed

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

Lines changed: 172 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,176 @@ 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 keepAliveIntervalSeconds 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 AwsIotMqtt5ClientBuilder after setting the keep alive interval.
684+
*/
685+
public AwsIotMqtt5ClientBuilder withKeepAliveIntervalSeconds(Long keepAliveIntervalSeconds)
686+
{
687+
this.configConnect.withKeepAliveIntervalSeconds(keepAliveIntervalSeconds);
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 AwsIotMqtt5ClientBuilder 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 time interval, in seconds, that the client requests the server to persist this connection's MQTT session state
710+
* for. Has no meaning if the client has not been configured to rejoin sessions. Must be non-zero in order to
711+
* successfully rejoin a session.
712+
*
713+
* If the responding ConnAckPacket contains a session expiry property value, then that is the negotiated session expiry
714+
* value. Otherwise, the session expiry sent by the client is the negotiated value.
715+
*
716+
* See <a href="https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901048">MQTT5 Session Expiry Interval</a>
717+
*
718+
* @param sessionExpiryIntervalSeconds A time interval, in seconds, that the client requests the server to persist this
719+
* connection's MQTT session state for.
720+
* @return The AwsIotMqtt5ClientBuilder after setting the session expiry interval.
721+
*/
722+
723+
public AwsIotMqtt5ClientBuilder withSessionExpiryIntervalSeconds(Long sessionExpiryIntervalSeconds)
724+
{
725+
this.configConnect.withSessionExpiryIntervalSeconds(sessionExpiryIntervalSeconds);
726+
return this;
727+
}
728+
729+
/**
730+
* Sets whether requests that the server send response information in the subsequent ConnAckPacket. This response
731+
* information may be used to set up request-response implementations over MQTT, but doing so is outside
732+
* the scope of the MQTT5 spec and client.
733+
*
734+
* See <a href="https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901052">MQTT5 Request Response Information</a>
735+
*
736+
* @param requestResponseInformation If true, requests that the server send response information in the subsequent ConnAckPacket.
737+
* @return The AwsIotMqtt5ClientBuilder after setting the request response information.
738+
*/
739+
public AwsIotMqtt5ClientBuilder withRequestResponseInformation(Boolean requestResponseInformation)
740+
{
741+
this.configConnect.withRequestResponseInformation(requestResponseInformation);
742+
return this;
743+
}
744+
745+
/**
746+
* Sets whether requests that the server send additional diagnostic information (via response string or
747+
* user properties) in DisconnectPacket or ConnAckPacket from the server.
748+
*
749+
* See <a href="https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901053">MQTT5 Request Problem Information</a>
750+
*
751+
* @param requestProblemInformation If true, requests that the server send additional diagnostic information
752+
* (via response string or user properties) in DisconnectPacket or ConnAckPacket from the server.
753+
* @return The AwsIotMqtt5ClientBuilder after setting the request problem information.
754+
*/
755+
public AwsIotMqtt5ClientBuilder withRequestProblemInformation(Boolean requestProblemInformation)
756+
{
757+
this.configConnect.withRequestProblemInformation(requestProblemInformation);
758+
return this;
759+
}
760+
761+
/**
762+
* Sets the maximum number of in-flight QoS 1 and 2 messages the client is willing to handle. If
763+
* omitted or null, then no limit is requested.
764+
*
765+
* See <a href="https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901049">MQTT5 Receive Maximum</a>
766+
*
767+
* @param receiveMaximum The maximum number of in-flight QoS 1 and 2 messages the client is willing to handle.
768+
* @return The AwsIotMqtt5ClientBuilder after setting the receive maximum.
769+
*/
770+
public AwsIotMqtt5ClientBuilder withReceiveMaximum(Long receiveMaximum)
771+
{
772+
this.configConnect.withReceiveMaximum(receiveMaximum);
773+
return this;
774+
}
775+
776+
/**
777+
* Sets the maximum packet size the client is willing to handle. If
778+
* omitted or null, then no limit beyond the natural limits of MQTT packet size is requested.
779+
*
780+
* See <a href="https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901050">MQTT5 Maximum Packet Size</a>
781+
*
782+
* @param maximumPacketSizeBytes The maximum packet size the client is willing to handle
783+
* @return The AwsIotMqtt5ClientBuilder after setting the maximum packet size.
784+
*/
785+
public AwsIotMqtt5ClientBuilder withMaximumPacketSizeBytes(Long maximumPacketSizeBytes)
786+
{
787+
this.configConnect.withMaximumPacketSizeBytes(maximumPacketSizeBytes);
788+
return this;
789+
}
790+
791+
/**
792+
* Sets the time interval, in seconds, that the server should wait (for a session reconnection) before sending the
793+
* will message associated with the connection's session. If omitted or null, the server will send the will when the
794+
* associated session is destroyed. If the session is destroyed before a will delay interval has elapsed, then
795+
* the will must be sent at the time of session destruction.
796+
*
797+
* See <a href="https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901062">MQTT5 Will Delay Interval</a>
798+
*
799+
* @param willDelayIntervalSeconds A time interval, in seconds, that the server should wait (for a session reconnection)
800+
* before sending the will message associated with the connection's session.
801+
* @return The AwsIotMqtt5ClientBuilder after setting the will message delay interval.
802+
*/
803+
public AwsIotMqtt5ClientBuilder withWillDelayIntervalSeconds(Long willDelayIntervalSeconds)
804+
{
805+
this.configConnect.withWillDelayIntervalSeconds(willDelayIntervalSeconds);
806+
return this;
807+
}
808+
809+
/**
810+
* Sets the definition of a message to be published when the connection's session is destroyed by the server or when
811+
* the will delay interval has elapsed, whichever comes first. If null, then nothing will be sent.
812+
*
813+
* See <a href="https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901040">MQTT5 Will</a>
814+
*
815+
* @param will The message to be published when the connection's session is destroyed by the server or when
816+
* the will delay interval has elapsed, whichever comes first.
817+
* @return The AwsIotMqtt5ClientBuilder after setting the will message.
818+
*/
819+
public AwsIotMqtt5ClientBuilder withWill(PublishPacket will)
820+
{
821+
this.configConnect.withWill(will);
822+
return this;
823+
}
824+
825+
/**
826+
* Sets the list of MQTT5 user properties included with the packet.
827+
*
828+
* See <a href="https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901054">MQTT5 User Property</a>
829+
*
830+
* @param userProperties List of MQTT5 user properties included with the packet.
831+
* @return The AwsIotMqtt5ClientBuilder after setting the user properties.
832+
*/
833+
public AwsIotMqtt5ClientBuilder withUserProperties(List<UserProperty> userProperties)
834+
{
835+
this.configConnect.withUserProperties(userProperties);
836+
return this;
837+
}
838+
667839
/**
668840
* Constructs an MQTT5 client object configured with the options set.
669841
* @return A MQTT5ClientOptions

0 commit comments

Comments
 (0)