Publishes a message to a specified topic.

publish(params)

Table 1. Request parameters
Parameter Type Description
params dict The parameter object. For more information, see the table Parameter descriptions of params.
Table 2. Parameter descriptions of params
Parameter Type Description
topic String The topic that receives the message.
payload String The message payload.
Table 3. Response parameters
Parameter Type Description
return dict The call is successful, a success message is returned. Otherwise, an error message is returned.
Note The success message only indicates that the call was successful, but does not indicate that the message was sent.

Sample requests

In the following example, each time an external event is triggered, a message is sent to the /topic/hello topic.

# -*- coding: utf-8 -*-
import lecoresdk

lesdk = lecoresdk.IoTData()

def handler(event, context):
  pub_params = {"topic": "/topic/hello",
              "payload": "Hello World"}
  lesdk.publish(pub_params)
  print("Publish message to /topic/hello.")
  return 'Hello world'