MQTT5 is the recommended MQTT Client. It has many benefits over MQTT311 outlined in the MQTT5 User Guide
- MQTT5 PubSub
- Direct MQTT with X509-based Mutual TLS Method
- Direct MQTT with Custom Authorizer Method
- Direct MQTT with PKCS11 Method
- Direct MQTT with PKCS12 Method
- Direct MQTT with Custom Key Operations Method
- Direct MQTT with Windows Certificate Store Method
- Direct MQTT with Java Keystore Method
- Websocket Connection with Sigv4 Authentication Method
- Websocket Connection with Cognito Authentication Method
- MQTT5 Shared Subscription
- MQTT5 Shadow
- MQTT5 Jobs
- MQTT5 Fleet Provisioning
- BasicPubSub
- Basic Connect
- Websocket Connect
- Pkcs11 Connect
- Pkcs12 Connect
- WindowsCert Connect
- X509 Connect
- CustomAuthorizer Connect
- JavaKeystore Connect
- Cognito Connect
- CustomKeyOperation Connect
- Shadow
- Jobs
- Fleet Provisioning
Note that all samples will show their options by passing in --help
. For example:
mvn compile exec:java -pl samples/BasicPubSub -Dexec.mainClass=pubsub.PubSub -Dexec.args='--help'
Additionally, you can enable logging in all samples. To enable logging in the samples, you will need to set the following system properties when running the samples:
-Daws.crt.debugnative=true
-Daws.crt.log.destination=File
-Daws.crt.log.level=Trace
-Daws.crt.log.filename=<path and filename>
aws.crt.debugnative
: Whether to debug native (C/C++) code. Can be eithertrue
orfalse
.aws.crt.log.destination
: Where the logs are outputted to. Can beFile
,Stdout
orStderr
. Defaults toStderr
.aws.crt.log.level
: The level of logging shown. Can beTrace
,Debug
,Info
,Warn
,Error
,Fatal
, orNone
. Defaults toWarn
.aws.crt.log.filename
: The path to save the log file. Only needed ifaws.crt.log.destination
is set toFile
.
For example, to run PubSub
with logging you could use the following:
mvn compile exec:java -pl samples/Mqtt5/PubSub -Daws.crt.debugnative=true -Daws.crt.log.level=Debug -Daws.crt.log.destionation=Stdout -Dexec.mainClass=pubsub.PubSub -Dexec.args='--endpoint <endpoint> --cert <path to cert> --key <path to key> --ca_file <path to ca file>'
If you want to run a sample using the latest release of the SDK, instead of compiled from source, you need to use the latest-release
profile. For example:
mvn -P latest-release compile exec:java -pl samples/Mqtt5/PubSub -Dexec.mainClass=mqtt5.pubsub.PubSub -Dexec.args='--endpoint <endpoint> --cert <path to certificate> --key <path to private key> --ca_file <path to root CA>'
This will run the sample using the latest released version of the SDK rather than the version compiled from source. If you are wanting to try the samples without first compiling the SDK, then make sure to add -P latest-release
and to have Maven download the Java V2 SDK. This works for all samples in the Java V2 SDK.