1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
// Code generated by smithy-go-codegen DO NOT EDIT.
package iotdataplane
import (
"context"
"fmt"
awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
"github.com/aws/aws-sdk-go-v2/service/iotdataplane/types"
"github.com/aws/smithy-go/middleware"
smithyhttp "github.com/aws/smithy-go/transport/http"
)
// Publishes an MQTT message. Requires permission to access the Publish (https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions)
// action. For more information about MQTT messages, see MQTT Protocol (http://docs.aws.amazon.com/iot/latest/developerguide/mqtt.html)
// in the IoT Developer Guide. For more information about messaging costs, see
// Amazon Web Services IoT Core pricing - Messaging (http://aws.amazon.com/iot-core/pricing/#Messaging)
// .
func (c *Client) Publish(ctx context.Context, params *PublishInput, optFns ...func(*Options)) (*PublishOutput, error) {
if params == nil {
params = &PublishInput{}
}
result, metadata, err := c.invokeOperation(ctx, "Publish", params, optFns, c.addOperationPublishMiddlewares)
if err != nil {
return nil, err
}
out := result.(*PublishOutput)
out.ResultMetadata = metadata
return out, nil
}
// The input for the Publish operation.
type PublishInput struct {
// The name of the MQTT topic.
//
// This member is required.
Topic *string
// A UTF-8 encoded string that describes the content of the publishing message.
ContentType *string
// 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.
// correlationData is an HTTP header value in the API.
CorrelationData *string
// 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 (https://docs.aws.amazon.com/general/latest/gr/iot-core.html#message-broker-limits)
// from the Amazon Web Services Reference Guide.
MessageExpiry int64
// The message body. MQTT accepts text, binary, and empty (null) message payloads.
// Publishing an empty (null) payload with retain = true deletes the retained
// message identified by topic from Amazon Web Services IoT Core.
Payload []byte
// An Enum string value that indicates whether the payload is formatted as UTF-8.
// payloadFormatIndicator is an HTTP header value in the API.
PayloadFormatIndicator types.PayloadFormatIndicator
// The Quality of Service (QoS) level. The default QoS level is 0.
Qos int32
// 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.
ResponseTopic *string
// 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 | false Default value: false
Retain bool
// 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. userProperties is an HTTP header value in the
// API. The following example userProperties parameter is a JSON string which
// represents two User Properties. Note that it needs to be base64-encoded:
// [{"deviceName": "alpha"}, {"deviceCnt": "45"}]
//
// This value conforms to the media type: application/json
UserProperties *string
noSmithyDocumentSerde
}
type PublishOutput struct {
// Metadata pertaining to the operation's result.
ResultMetadata middleware.Metadata
noSmithyDocumentSerde
}
func (c *Client) addOperationPublishMiddlewares(stack *middleware.Stack, options Options) (err error) {
if err := stack.Serialize.Add(&setOperationInputMiddleware{}, middleware.After); err != nil {
return err
}
err = stack.Serialize.Add(&awsRestjson1_serializeOpPublish{}, middleware.After)
if err != nil {
return err
}
err = stack.Deserialize.Add(&awsRestjson1_deserializeOpPublish{}, middleware.After)
if err != nil {
return err
}
if err := addProtocolFinalizerMiddlewares(stack, options, "Publish"); err != nil {
return fmt.Errorf("add protocol finalizers: %v", err)
}
if err = addlegacyEndpointContextSetter(stack, options); err != nil {
return err
}
if err = addSetLoggerMiddleware(stack, options); err != nil {
return err
}
if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
return err
}
if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
return err
}
if err = addResolveEndpointMiddleware(stack, options); err != nil {
return err
}
if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
return err
}
if err = addRetryMiddlewares(stack, options); err != nil {
return err
}
if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
return err
}
if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
return err
}
if err = addClientUserAgent(stack, options); err != nil {
return err
}
if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
return err
}
if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
return err
}
if err = addSetLegacyContextSigningOptionsMiddleware(stack); err != nil {
return err
}
if err = addOpPublishValidationMiddleware(stack); err != nil {
return err
}
if err = stack.Initialize.Add(newServiceMetadataMiddleware_opPublish(options.Region), middleware.Before); err != nil {
return err
}
if err = awsmiddleware.AddRecursionDetection(stack); err != nil {
return err
}
if err = addRequestIDRetrieverMiddleware(stack); err != nil {
return err
}
if err = addResponseErrorMiddleware(stack); err != nil {
return err
}
if err = addRequestResponseLogging(stack, options); err != nil {
return err
}
if err = addDisableHTTPSMiddleware(stack, options); err != nil {
return err
}
return nil
}
func newServiceMetadataMiddleware_opPublish(region string) *awsmiddleware.RegisterServiceMetadata {
return &awsmiddleware.RegisterServiceMetadata{
Region: region,
ServiceID: ServiceID,
OperationName: "Publish",
}
}
|