public static AwsIotMqtt5ClientBuilder newMqttBuilderFromMqtt311ConnectionConfig()

in sdk/src/main/java/software/amazon/awssdk/iot/AwsIotMqtt5ClientBuilder.java [365:407]


    public static AwsIotMqtt5ClientBuilder newMqttBuilderFromMqtt311ConnectionConfig(MqttConnectionConfig mqtt311Config, TlsContextOptions tlsOptions) throws Exception {

        if (mqtt311Config.getEndpoint() == null) {
            throw new Exception("MQTT311 to MQTT5 builder requires MQTT311 to have a endpoint set");
        }
        if (tlsOptions == null) {
            throw new Exception("MQTT311 to MQTT5 builder requires MQTT311 to TLS options passed");
        }

        AwsIotMqtt5ClientBuilder builder = new AwsIotMqtt5ClientBuilder(mqtt311Config.getEndpoint(), (long)mqtt311Config.getPort(), tlsOptions);
        if (tlsOptions.isAlpnSupported()) {
            builder.configTls.withAlpnList("x-amzn-mqtt-ca");
        }

        if (mqtt311Config.getUseWebsockets() == true) {
            throw new Exception("MQTT311 to MQTT5 builder does not support MQTT311 websockets");
        }
        if (mqtt311Config.getWillMessage() != null) {
            throw new Exception("MQTT311 to MQTT5 builder does not support MQTT311 Will messages");
        }

        ConnectPacketBuilder connectPacket = new ConnectPacketBuilder();
        if (mqtt311Config.getClientId() != null) {
            connectPacket.withClientId(mqtt311Config.getClientId());
        }
        connectPacket.withKeepAliveIntervalSeconds((long)mqtt311Config.getKeepAliveSecs());
        if (mqtt311Config.getUsername() != null) {
            connectPacket.withUsername(mqtt311Config.getUsername());
        }
        if (mqtt311Config.getPassword() != null) {
            connectPacket.withPassword(mqtt311Config.getPassword().getBytes());
        }
        builder.withConnectProperties(connectPacket);

        builder.withHttpProxyOptions(mqtt311Config.getHttpProxyOptions());
        builder.withMaxReconnectDelayMs(mqtt311Config.getMaxReconnectTimeoutSecs() * 1000); // Seconds to milliseconds
        builder.withMinReconnectDelayMs(mqtt311Config.getMinReconnectTimeoutSecs() * 1000); // Seconds to milliseconds
        builder.withPingTimeoutMs((long)mqtt311Config.getPingTimeoutMs());
        builder.withAckTimeoutSeconds((long)mqtt311Config.getProtocolOperationTimeoutMs() * 1000); // Seconds to milliseconds
        builder.withSocketOptions(mqtt311Config.getSocketOptions());

        return builder;
    }