使用IoT规则SQL一次查询多个主题 [英] Query multiple Topics at once using IoT Rule SQL

查看:67
本文介绍了使用IoT规则SQL一次查询多个主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个结果主题,其中消息几乎几乎同时"从不同的来源到达.

I have two result topics where messages arrive from different sources "almost nearly at the same time".

主题:sensor1/result-接收有效载荷-> { "output_from_sensor1": {"result":"OK"} }
主题:sensor2/result-接收有效载荷-> { "output_from_sensor2": {"result":"OK"} }

Topic: sensor1/result --receiving payload--> { "output_from_sensor1": {"result":"OK"} }
Topic: sensor2/result --receiving payload--> { "output_from_sensor2": {"result":"OK"} }

我想创建一个AWS IoT规则,该规则在一个查询中同时扫描"这两个主题.并采取行动.

I would like to create an AWS IoT Rule which scans these two topics "simultaneously in one query" and take an action.

在此过程中,我尝试了这些物联网查询(据我对SQL语法的了解),但到目前为止还没有运气:(

During the way, I have tried these IoT queries (from my knowledge of SQL syntax) but no luck so far :(

SELECT output_from_sensor1.result AS final_output.result FROM ‘sensor1/result’ WHERE (SELECT output_from_sensor2.result FROM ‘sensor2/result’)=‘OK’

(SELECT output_from_sensor1.result FROM 'sensor1/result') UNION (SELECT output_from_sensor2.result FROM 'sensor2/result')

非常感谢!

推荐答案

AWS IoT规则由一条MQTT消息触发,并且规则操作仅处理触发该规则的消息.因此,尽管+# 通配符可以用于从多个主题中选择,每次调用规则仅处理一条消息.

AWS IoT rules are triggered by a single MQTT message and the rule actions only process the message that triggered the rule. So while the + and # Wildcards can be used to select from multiple topics, each invocation of the rule only handles one message.

您可能在一个查询中扫描多个主题"的假设意味着涉及多个消息(针对每个主题).

Your assumption that it is possible to 'scan multiple topics' in one query implies that multiple messages are involved (to each topic).

根据您要解决的问题,将消息缓冲在队列中(例如SQS)可能很有意义.然后,该处理可以检查给定时间窗口中是否显示多条消息,以对这两条消息执行单个操作.

Depending on the problem you are trying to solve, it may make sense to buffer the messages in a queue (e.g. SQS). The processing can then check if multiple messages appear in a given time window to perform a single action on both messages.

我不确定AWS IoT SQL是否支持扫描多个主题".在一个查询中.在AWS文档中找不到此类引用.

I am not sure if AWS IoT SQL support "scanning multiple topics" in one query. No such references found in AWS docs.

我没有在文档中找到明确的说法来排除这种情况.但是措辞与一条消息触发的规则是一致的.

I haven't found a definitive statement in the documentation that rules this out. But the wording is consistent with a rule being triggered by one message.

例如从规则教程

当在主题上收到与主题过滤器匹配的MQTT消息时,将触发规则.

The rule is triggered when an MQTT message that matches the topic filter is received on a topic.

FROM条款订阅了使用MQTT +#通配符对主题或主题过滤器设置规则.

The FROM Clause subscribes the rule to a topic or topic filter using the MQTT + and # wildcards.

操作符,如ANDOR,但在FROM子句中未使用它们.运营商文档指出:

There are operators like AND and OR but these are not used in the FROM clause. The operators documentation states:

可以在SELECT和WHERE子句中使用以下运算符.

The following operators can be used in SELECT and WHERE clauses.

这篇关于使用IoT规则SQL一次查询多个主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆