publish
¶
publish(
topic: Topic,
*,
config_overrides: Optional[IoTDataPlaneClientConfig] = None,
qos: Optional[Qos] = None,
retain: Optional[Retain] = None,
payload: Optional[Payload] = None,
user_properties: Optional[SynthesizedJsonUserProperties] = None,
payload_format_indicator: Optional[PayloadFormatIndicator] = None,
content_type: Optional[ContentType] = None,
response_topic: Optional[ResponseTopic] = None,
correlation_data: Optional[CorrelationData] = None,
message_expiry: Optional[MessageExpiry] = None,
) -> None
Publishes an MQTT message.
Requires permission to access the Publish action.
For more information about MQTT messages, see MQTT Protocol in the IoT Developer Guide.
For more information about messaging costs, see Amazon Web Services IoT Core pricing - Messaging.
Parameters:
-
topic(Topic) –The name of the MQTT topic.
-
qos(Optional[Qos], default:None) –The Quality of Service (QoS) level. The default QoS level is 0.
-
retain(Optional[Retain], default:None) –A Boolean value that determines whether to set the RETAIN flag when the message is published.
Setting the RETAIN flag causes the message to be retained and sent to new subscribers to the topic.
Valid values:
true|falseDefault value:
false -
payload(Optional[Payload], default:None) –The message body. MQTT accepts text, binary, and empty (null) message payloads.
Publishing an empty (null) payload with retain =
truedeletes the retained message identified by topic from Amazon Web Services IoT Core. -
user_properties(Optional[SynthesizedJsonUserProperties], default:None) –A JSON string that contains an array of JSON objects. If you don’t use Amazon Web Services SDK or CLI, you must encode the JSON string to base64 format before adding it to the HTTP header.
userPropertiesis an HTTP header value in the API.The following example
userPropertiesparameter is a JSON string which represents two User Properties. Note that it needs to be base64-encoded:[{"deviceName": "alpha"}, {"deviceCnt": "45"}] -
payload_format_indicator(Optional[PayloadFormatIndicator], default:None) –An
Enumstring value that indicates whether the payload is formatted as UTF-8.payloadFormatIndicatoris an HTTP header value in the API. -
content_type(Optional[ContentType], default:None) –A UTF-8 encoded string that describes the content of the publishing message.
-
response_topic(Optional[ResponseTopic], default:None) –A UTF-8 encoded string that's used as the topic name for a response message. The response topic is used to describe the topic which the receiver should publish to as part of the request-response flow. The topic must not contain wildcard characters.
-
correlation_data(Optional[CorrelationData], default:None) –The base64-encoded binary data used by the sender of the request message to identify which request the response message is for when it's received.
correlationDatais an HTTP header value in the API. -
message_expiry(Optional[MessageExpiry], default:None) –A user-defined integer value that represents the message expiry interval in seconds. If absent, the message doesn't expire. For more information about the limits of
messageExpiry, see Amazon Web Services IoT Core message broker and protocol limits and quotas from the Amazon Web Services Reference Guide.
Raises:
-
InternalFailureException–An unexpected error has occurred.
-
InvalidRequestException–The request is not valid.
-
MethodNotAllowedException–The specified combination of HTTP verb and URI is not supported.
-
ThrottlingException–The rate exceeds the limit.
-
UnauthorizedException–You are not authorized to perform this operation.
-
UnknownServiceError–The service returned an error code this client does not model.
Source code in docs_src/capo_iot_data_plane/_services/io_t_data_plane.py
692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 | |