Skip to main content

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

ParameterTypeExplanation
dataObjectThe data that gets sent in the message
messagetypeStringThe message_type of the message (located in headers/metadata)
splitArraysBooleanIf 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)