The action is used for publishing output message into EdgeX message bus.
**Please notice that, if you're using the ZeorMQ message bus, the action will create a NEW EdgeX message bus (with the address where running eKuiper service), but not by leveraging the original message bus (normally it's the address & port exposed by application service). **
Also, you need to expose the port number to host server before running the eKuiper server if you want to have the service available to other hosts.
Property name | Optional | Description |
---|---|---|
protocol | true | The protocol. If it's not specified, then use default value tcp . |
host | true | The host of message bus. If not specified, then use default value * . |
port | true | The port of message bus. If not specified, then use default value 5563 . |
topic | true | The topic to be published. If not specified, then use default value events . |
contentType | true | The content type of message to be published. If not specified, then use the default value application/json . |
metadata | true | The property is a field name that allows user to specify a field name of SQL select clause, the field name should use meta(*) AS xxx to select all of EdgeX metadata from message. |
deviceName | true | Allows user to specify the device name in the event structure that are sent from eKuiper. |
profileName | true | Allows user to specify the profile name in the event structure that are sent from Kuiper. |
type | true | The message bus type, two types of message buses are supported, zero or mqtt , and zero is the default value. |
optional | true | If mqtt message bus type is specified, then some optional values can be specified. Please refer to below for supported optional supported configurations. |
Below optional configurations are supported, please check MQTT specification for the detailed information.
In this case, the original metadata value (such as id, deviceName, profileName, sourceName, origin, tags
in Events
structure, and id, deviceName, profileName, origin, valueType
in Reading
structure will not be kept). eKuiper acts as another EdgeX micro service here, and it has own device name
and profile name
. deviceName
and profileName
properties are provided, and allows user to specify the device name of eKuiper. The SourceName
will be default to the topic
property. Below is one example,
1) Data received from EdgeX message bus events
topic,
{
"DeviceName": "demo", "Origin": 000, …
"readings":
[
{"ResourceName": "Temperature", value: "30", "Origin":123 …},
{"ResourceName": "Humidity", value: "20", "Origin":456 …}
]
}
2) Use following rule, and specify deviceName
with kuiper
and profileName
with kuiperProfile
in edgex
action.
{
"id": "rule1",
"sql": "SELECT temperature * 3 AS t1, humidity FROM events",
"actions": [
{
"edgex": {
"protocol": "tcp",
"host": "*",
"port": 5571,
"topic": "application",
"deviceName": "kuiper",
"profileName": "kuiperProfile",
"contentType": "application/json"
}
}
]
}
3) The data sent to EdgeX message bus.
{
"DeviceName": "kuiper", "ProfileName": "kuiperProfile", "Origin": 0, …
"readings":
[
{"ResourceName": "t1", value: "90", "Origin": 0 …},
{"ResourceName": "humidity", value: "20" , "Origin": 0 …}
]
}
Please notice that,
Event
structure is changed to kuiper
and the profile name is changed to kuiperProfile
.Events and Readings
structure will be updated with new value. Origin
field is updated to another value generated by eKuiper (here is 0
).But for some scenarios, you may want to keep some of original metadata. Such as keep the device name as original value that published to eKuiper (demo
in the sample), and also other metadata of readings arrays. In such case, eKuiper is acting as a filter - to filter NOT concerned messages, but still keep original data.
Below is an example,
1) Data received from EdgeX message bus events
topic,
{
"DeviceName": "demo", "Origin": 000, …
"readings":
[
{"ResourceName": "Temperature", value: "30", "Origin":123 …},
{"ResourceName": "Humidity", value: "20", "Origin":456 …}
]
}
2) Use following rule, and specify metadata
with edgex_meta
in edgex
action.
{
"id": "rule1",
"sql": "SELECT meta(*) AS edgex_meta, temperature * 3 AS t1, humidity FROM events WHERE temperature > 30",
"actions": [
{
"edgex": {
"protocol": "tcp",
"host": "*",
"port": 5571,
"topic": "application",
"metadata": "edgex_meta",
"contentType": "application/json"
}
}
]
}
Please notice that,
meta(*) AS edgex_meta
in the SQL clause, the meta(*)
returns all of metadata.edgex
action, value edgex_meta
is specified for metadata
property. This property specifies which field contains metadata of message.3) The data sent to EdgeX message bus.
{
"DeviceName": "demo", "Origin": 000, …
"readings":
[
{"ResourceName": "t1", value: "90" , "Origin": 0 …},
{"ResourceName": "humidity", value: "20", "Origin":456 …}
]
}
Please notice that,
Events
structure is still kept, such as DeviceName
& Origin
.humidity
metadata will be the old values
received from EdgeX message bus.t1
in the sample will fill with default value that generated by eKuiper.SELECT avg(temperature) AS temperature, meta(*) AS edgex_meta FROM ... GROUP BY TUMBLINGWINDOW(ss, 10)
.
In this case, there are possibly several messages in the window, the metadata value for temperature
will be filled with value from 1st message that received from bus.Below is a rule that send analysis result to MQTT message bus, please notice how to specify ClientId
in optional
configuration.
{
"id": "rule1",
"sql": "SELECT meta(*) AS edgex_meta, temperature, humidity, humidity*2 as h1 FROM demo WHERE temperature = 20",
"actions": [
{
"edgex": {
"protocol": "tcp",
"host": "127.0.0.1",
"port": 1883,
"topic": "result",
"type": "mqtt",
"metadata": "edgex_meta",
"contentType": "application/json",
"optional": {
"ClientId": "edgex_message_bus_001"
}
}
},
{
"log":{}
}
]
}