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 Antworten
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
beantwortet vor 2 Jahren
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
beantwortet vor 2 Jahren
0

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

AWS
beantwortet vor 2 Jahren
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
beantwortet vor einem Jahr

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen