- Le plus récent
- Le plus de votes
- La plupart des commentaires
The Java SDK doesn't support subscribing. The Java SDK is a relatively thin wrapper around the AWS services API (HTTPS). There is no API for subscribing: https://docs.aws.amazon.com/iot/latest/apireference/API_Operations_AWS_IoT_Data_Plane.html
To subscribe, you would need to connect to the AWS IoT Core MQTT broker. As Ryan_B has indicated elsewhere, one solution is to use the device SDK: https://github.com/aws/aws-iot-device-sdk-java-v2/tree/main/samples#basicpubsub
However, do you have need of receiving messages in real-time? It's not so common for web applications to connect directly to IoT Core. Solutions are often architected such that incoming device messages would typically flow through IoT Core to Rules Engine and then to another AWS service. Perhaps Kinesis, SQS or a storage service. Decoupling the application from the flow of incoming messages. The application would then retrieve the data from these other services, often through API gateway. Something like this: https://docs.aws.amazon.com/solutions/latest/smart-product-solution/architecture.html .
Amplify is also a popular choice: https://docs.amplify.aws/lib/pubsub/getting-started/q/platform/js/
Thanks for the response. I have installed the package you suggested, and gotten the publish and subscribe functions to work.
My use case is fairly simple and most of the messages will be flowing from my application to the devices. I plan to use the device "shadows" for this communication. As an FYI, my application is not a web application, rather, it is a mobile application with a server that is hosted on EC2 (and it is the EC2 instance that connects to IoT core on behalf of the app user, not the app itself).
I do have one infrequent use case where a device needs to signal back an alarm condition, which needs to be acted on quickly. My thinking is that I'll have all of the devices send that alarm to a common message queue, which I will monitor on my server. Does this sound feasible? I haven't tried it yet, but I don't think there's anything that would prevent me from having all of my devices publish messages to some standard queue such as "alarm".
As far as the other Amazon services you mention, I haven't looked at them yet but I'm not sure I'll really need them given the simplicity of what I'm doing. I'll certainly keep them in mind if more complex interactions are needed later.
Contenus pertinents
- demandé il y a 2 ans
- demandé il y a 4 mois
- AWS OFFICIELA mis à jour il y a 3 ans
- AWS OFFICIELA mis à jour il y a 3 ans
- AWS OFFICIELA mis à jour il y a 9 mois
- AWS OFFICIELA mis à jour il y a 2 ans
So far I've been able to retrieve and update shadows using IotDataPlaneClient, and I can also publish messages. What I'm struggling with is that although I can publish, I can't subscribe. It's essential that I be able to subscribe. How is this accomplished?