Getting started with MQTT client in Java SDK?

0

Hi,

I'm working with IOT services using the Java SDK. I'm able to instantiate an IotClient (software.amazon.awssdk.services.iot.IotClient) and perform some basic functions like listThings() or describeEndpoint(). So I know my integration and credentials are working as expected.

The next thing I need to do is work with the message queues (MQTT) associated with my IOT things. I'm a bit confused here. I see that there is a package called mq, which contains an MqClient; I've imported that package into my project and I can create the MqClient (and I've also made sure my credentials have full access to MQ). I'm not sure what to do next. The MqClient doesn't appear to have any functions related to sending or receiving messages. I'm also not sure how to configure it to work with the message queues used by IOT services, as opposed to others.

Do I need some kind of third-party MQTT client? I've noticed that some are available and I think MQ is a non-proprietary protocol, but I'd definitely prefer to steer clear of random third-party pacakges if the functionality I need is available from the AWS Java SDK.

Thanks, Frank

Frank
demandé il y a 2 ans1095 vues
3 réponses
1

The main AWS SDK for Java includes a client for interacting with the control plane APIs of AWS IoT Core, such as ListThings and DescribeEndpoint as you have found. It also includes some limited functionality for the data plane, such as publishing a new message over the HTTP API and GET/POST APIs for interacting with the device shadow service. If you are looking for full bi-directional pubsub, you may want to use the AWS IoT Device SDK for Java: https://github.com/aws/aws-iot-device-sdk-java-v2

AWS
Ryan_B
répondu il y a 2 ans
0

I'm confused as to how to construct the AwsIotMqttConnectionBuilder. It seems to require a certificate and a private key. I have an AWS access key and secret key. How do I convert that into the credentials that this class requires?

Frank
répondu il y a 2 ans
  • I should add that what I'm trying to do is create a Java server application that can access all of my devices simultaneously. I know that individual devices have certificates, but I'm not trying to emulate a device, I'm trying to build a supervisor application that can receive and send messages from and to any device. Is this even possible?

  • Yes, that is supported. If your server app has AWS IAM AK/SK to use, you want to connect your app using MQTT over websockets instead of x509 certificate. If you use the withWebsockets() flag on AwsIotMqttConnectionBuilder, I believe it will default the CredentialsProvider to use system env AK/SK. You can override and provide your own CredentialsProvider using withWebsocketCredentialsProvider().

0

Thanks for the response. I'm lookin at the AWS IoT Device SDK, but immediately running into the issue that the classes it uses, such as "software.amazon.awssdk.crt.CRT", are not recongized when I try to import them into my project. Do you know which Gradle packages I need to include to get them?

Frank
répondu il y a 2 ans

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions