Can I get a list of iOT topics?

0

I'm working with IOT services using the Java SDK. The main class I'm using is software.amazon.awssdk.services.iot.IotClient.

Is there a way to get a list of MQTT topics via the SDK? I can see that there is a function to listTopicRules, but I don't see anything to list the topics themselves.

Thanks, Frank

  • I found some sample code that uses a class called "software.amazon.awssdk.crt.mqtt.MqttClientConnection". However, this package doesn't seem to exist anymore; it's not in the documentation or available in my project.

4 Answers
0

MQTT topics are ephemeral in that clients simply specify them in publish and subscribe operations. The service does not provide APIs listing topics that your clients are currently using. For reserved service topics defined by AWS IoT services, you can refer to https://docs.aws.amazon.com/iot/latest/developerguide/reserved-topics.html

AWS
Ryan_B
answered 2 years ago
0

Thanks. Regardless of the list of topics, which client or package do I need to publish and subscribe?

I'm a bit confused about the AWS client in general. There seems to be a 1.x version and a 2.x version. I assumed I should use the 2.x version, but most of the examples I can find don't work; I think it's because they're written against the 1.x API. What should I do?

Frank
answered 2 years ago
0

You should favor 2.x version. Which AWS IoT SDK are you using?

AWS
answered 2 years ago
0

You may use IoT Java Client Library. Here is the sample code:

import com.amazonaws.services.iot.client.AWSIotException; import com.amazonaws.services.iot.client.AWSIotMqttClient; import com.amazonaws.services.iot.client.AWSIotTopic;

public class MQTTTopicList { public static void main(String[] args) { AWSIotMqttClient client = new AWSIotMqttClient("<AWS IoT endpoint>", "<client id>", "<AWS access key>", "<AWS secret key>"); try { client.connect(); for (AWSIotTopic topic : client.getTopics()) { System.out.println(topic.getTopic()); } } catch (AWSIotException e) { e.printStackTrace(); } finally { client.disconnect(); } } }

AWS
GA
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions