Reputation: 1300
I'm trying to develop a lambda function in C# to process and transform the data which I receive from AWS IoT core in the same way I did with the data from DynamoDB, S3 or SQS for example.
What I would like to know is if I have to subscribe to the topic obligatorily, transform each message and finally send it to s3, DyanmoDB or whatever or I can access directly to this data without subscribe.
The code:
var CaCert = X509Certificate.CreateFromCertFile(@"C:\...\rootCA.pem");
var clientCert = new X509Certificate2(@"C:\...\amazon.pfx");
string ClientID = Guid.NewGuid().ToString();
var IotClient = new MqttClient(IotEndPoint, BrokerPort, true, CaCert, clientCert, MqttSslProtocols.TLSv1_2);
IotClient.MqttMsgPublishReceived += Client_MqttMsgPublishReceived;
IotClient.Connect(ClientID);
Console.WriteLine("Connected to IoT Core. Waiting for the frames...");
IotClient.Subscribe(new string[] { topic }, new byte[] { MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE });
Upvotes: 0
Views: 837
Reputation: 200657
You have to subscribe to the topic(s) to access the data. However, you can simply write your topic subscription SQL expression to use a wildcard like this example from the official documentation to avoid having to subscribe to each individual topic:
You can use the # wildcard character to match any subpath in a topic filter:
Example:
Incoming payload published on topic 'a/b': {temperature: 50}.
Incoming payload published on topic 'a/c': {temperature: 60}.
Incoming payload published on topic 'a/e/f': {temperature: 70}.
Incoming payload published on topic 'b/x': {temperature: 80}.
SQL: "SELECT temperature AS t FROM 'a/#'".
The rule is subscribed to any topic beginning with 'a', so it is executed three times, sending outgoing payloads of {t: 50} (for a/b), {t: 60} (for a/c), and {t: 70} (for a/e/f) to its actions. It is not subscribed to 'b/x', so the rule will not be triggered for the {temperature: 80} message.
Upvotes: 1