Class Mqtt5Client

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public class Mqtt5Client
    extends CrtResource
    This class wraps the aws-c-mqtt MQTT5 client to provide the basic MQTT5 pub/sub functionalities via the AWS Common Runtime One Mqtt5Client class creates one connection.
    • Constructor Detail

      • Mqtt5Client

        public Mqtt5Client​(Mqtt5ClientOptions options)
                    throws CrtRuntimeException
        Creates a Mqtt5Client instance using the provided Mqtt5ClientOptions. Once the Mqtt5Client is created, changing the settings will not cause a change in already created Mqtt5Client's.
        Parameters:
        options - The Mqtt5Options class to use to configure the new Mqtt5Client.
        Throws:
        CrtRuntimeException - If the system is unable to allocate space for a native MQTT5 client structure
    • Method Detail

      • start

        public void start()
                   throws CrtRuntimeException
        Notifies the Mqtt5Client that you want it maintain connectivity to the configured endpoint. The client will attempt to stay connected using the properties of the reconnect-related parameters in the Mqtt5Client configuration. This is an asynchronous operation.
        Throws:
        CrtRuntimeException - If the native client returns an error when starting
      • stop

        public void stop​(DisconnectPacket disconnectPacket)
                  throws CrtRuntimeException
        Notifies the Mqtt5Client that you want it to end connectivity to the configured endpoint, disconnecting any existing connection and halting any reconnect attempts. This is an asynchronous operation.
        Parameters:
        disconnectPacket - (optional) Properties of a DISCONNECT packet to send as part of the shutdown process. When disconnectPacket is null, no DISCONNECT packets will be sent.
        Throws:
        CrtRuntimeException - If the native client is unable to initialize the stop process.
      • stop

        public void stop()
                  throws CrtRuntimeException
        Notifies the Mqtt5Client that you want it to end connectivity to the configured endpoint, disconnecting any existing connection and halting any reconnect attempts. No DISCONNECT packets will be sent. This is an asynchronous operation.
        Throws:
        CrtRuntimeException - If the native client is unable to initialize the stop process.
      • publish

        public java.util.concurrent.CompletableFuture<PublishResult> publish​(PublishPacket publishPacket)
        Tells the Mqtt5Client to attempt to send a PUBLISH packet. Will return a future containing a PublishPacket if the publish is successful. The data in the PublishPacket varies depending on the QoS of the Publish. For QoS 0, the PublishPacket will not contain data. For QoS 1, the PublishPacket will contain a PubAckPacket. See PublishPacket class documentation for more info.
        Parameters:
        publishPacket - PUBLISH packet to send to the server
        Returns:
        A future that will be rejected with an error or resolved with a PublishResult response
      • subscribe

        public java.util.concurrent.CompletableFuture<SubAckPacket> subscribe​(SubscribePacket subscribePacket)
        Tells the Mqtt5Client to attempt to subscribe to one or more topic filters.
        Parameters:
        subscribePacket - SUBSCRIBE packet to send to the server
        Returns:
        a future that will be rejected with an error or resolved with the SUBACK response
      • unsubscribe

        public java.util.concurrent.CompletableFuture<UnsubAckPacket> unsubscribe​(UnsubscribePacket unsubscribePacket)
        Tells the Mqtt5Client to attempt to unsubscribe from one or more topic filters.
        Parameters:
        unsubscribePacket - UNSUBSCRIBE packet to send to the server
        Returns:
        a future that will be rejected with an error or resolved with the UNSUBACK response
      • getOperationStatistics

        public Mqtt5ClientOperationStatistics getOperationStatistics()
        Returns statistics about the current state of the Mqtt5Client's queue of operations.
        Returns:
        Current state of the client's queue of operations.
      • getIsConnected

        public boolean getIsConnected()
        Returns the connectivity state for the Mqtt5Client.
        Returns:
        True if the client is connected, false otherwise
      • getClientOptions

        public Mqtt5ClientOptions getClientOptions()
        Returns the Mqtt5ClientOptions used for the Mqtt5Client
        Returns:
        Mqtt5ClientOptions