api.publish
api.publish(data [,messagetype] [,splitArrays])
Description
Publishes data as message(s) to the 1Gateway message bus. The arguments can either be (data), (data, messageType), (data, splitArrays) or (data, messageType, splitArrays).
Parameters
| Parameter | Type | Explanation |
|---|---|---|
| data | Object | The data that gets sent in the message |
| messagetype | String | The message_type of the message (located in headers/metadata) |
| splitArrays | Boolean | If true, it will split an array into multiple message instead of one |
Example
alarmsjson = '''[{
"timestamp" : 1525335049,
"type" : "Spectrum",
"name" : "ES",
"id" : "ES",
"element" : "Madrid",
"sev" : "3",
"eventtype" : "temperature",
"txt": "hello there",
"status": "OK",
"suppressionkey": 1
},
{
"timestamp" : 1525345049,
"type" : "Spectrum",
"name" : "ES"
, "id" : "ES",
"element" : "Barcelona",
"sev" : "3",
"eventtype" : "temperature",
"txt": "hello there",
"status": "NOTOK",
"suppressionkey": 2
}]'''
api.publish(alarmsjson, "Alarm", true)