send_direct_message
¶
send_direct_message(
client_id: ClientId,
topic: Topic,
*,
config_overrides: Optional[IoTDataPlaneClientConfig] = None,
content_type: Optional[ContentType] = None,
response_topic: Optional[ResponseTopic] = None,
confirmation: Optional[Confirmation] = None,
timeout: Optional[TimeoutInSeconds] = None,
payload: Optional[Payload] = None,
user_properties: Optional[SynthesizedJsonUserProperties] = None,
payload_format_indicator: Optional[PayloadFormatIndicator] = None,
correlation_data: Optional[CorrelationData] = None,
) -> SendDirectMessageResponse
Sends an MQTT message directly to a specific client identified by its client ID.
SendDirectMessage targets a single client ID. The receiving client does not need to subscribe to the topic, but the receiver's policy must allow iot:Receive on the specified topic.
Requires permission to access the SendDirectMessage action.
For more information about messaging costs, see Amazon Web Services IoT Core pricing.
Parameters:
-
client_id(ClientId) –The unique identifier of the MQTT client to send the message to.
Client IDs must not exceed 128 characters and can't start with a dollar sign ($). MQTT client IDs must be URL encoded (percent-encoded) when they contain characters that are not valid in HTTP requests, such as spaces, forward slashes (/), and UTF-8 characters. For more information, see Amazon Web Services IoT Core message broker and protocol limits and quotas.
-
topic(Topic) –The topic of the outbound MQTT Publish message to the receiving client. For more information, see Amazon Web Services IoT Core message broker and protocol limits and quotas.
-
content_type(Optional[ContentType], default:None) –The MQTT5 content type property forwarded to the receiving client (for example,
application/json). -
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 describes the topic which the receiver should publish to as part of the request-response flow. The topic must not contain wildcard characters. For more information, see Amazon Web Services IoT Core message broker and protocol limits and quotas.
-
confirmation(Optional[Confirmation], default:None) –A Boolean value that specifies whether to wait for delivery confirmation from the receiving client.
When set to
true, the API delivers the message at QoS 1 and waits for the client to send a delivery confirmation (PUBACK) before returning a successful response. If delivery confirmation is not received within the specifiedtimeoutperiod, the API returns HTTP 504.When set to
false, the API delivers the message at QoS 0 and returns after Amazon Web Services IoT Core attempts to deliver the message.Valid values:
true|falseDefault value:
false -
timeout(Optional[TimeoutInSeconds], default:None) –An integer that represents the maximum time, in seconds, to wait for a delivery confirmation (PUBACK) from the receiving client after the message has been delivered. This parameter is only used when
confirmationis set totrue. Ifconfirmationisfalse, this parameter is ignored.The total API response time may be higher than this value due to internal processing. Set your HTTP client timeout to a value greater than this parameter.
Valid range: 1 to 15 seconds.
Default value:
5seconds. -
payload(Optional[Payload], default:None) –The message body. MQTT accepts text, binary, and empty (null) message payloads.
-
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.For MQTT 3.1.1 clients, user properties are silently dropped.
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. -
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.
Raises:
-
ForbiddenException–The caller isn't authorized to make the request.
-
GatewayTimeoutException–The delivery confirmation was not received from the client within the specified timeout period.
-
InternalFailureException–An unexpected error has occurred.
-
InvalidRequestException–The request is not valid.
-
RequestEntityTooLargeException–The payload exceeds the maximum size allowed.
-
ResourceNotFoundException–The specified resource does not exist.
-
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
787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 | |