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回答
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年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ