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.

Frank
已提問 2 年前檢視次數 1067 次
4 個答案
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
已回答 2 年前
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
已回答 2 年前
0

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

AWS
已回答 2 年前
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
已回答 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南