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
답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠