Documentation ¶
Index ¶
- Constants
- func ErrorMsg(msgBody string) (*messages.ErrorMsg, bool)
- func ReferenceMsg(msgBody string) (*messages.ReferenceMsg, bool)
- type Option
- type SnsClientWrapper
- type SqsClientWrapper
- func (wrapper *SqsClientWrapper) DeleteHeftyMessage(ctx context.Context, params *sqs.DeleteMessageInput, ...) (*sqs.DeleteMessageOutput, error)
- func (wrapper *SqsClientWrapper) ReceiveHeftyMessage(ctx context.Context, params *sqs.ReceiveMessageInput, ...) (*sqs.ReceiveMessageOutput, error)
- func (wrapper *SqsClientWrapper) SendHeftyMessage(ctx context.Context, params *sqs.SendMessageInput, ...) (*sqs.SendMessageOutput, error)
- func (wrapper *SqsClientWrapper) SendHeftyMessageBatch(ctx context.Context, params *sqs.SendMessageBatchInput, ...) (*sqs.SendMessageBatchOutput, error)
Constants ¶
const ( MaxAwsMessageLengthBytes = 262_144 // 256KB; used for both SQS and SNS MaxHeftyMessageLengthBytes = 33_554_432 // 32MB )
Variables ¶
This section is empty.
Functions ¶
func ErrorMsg ¶
ErrorMsg determines if a message body is an error message and returns a struct holding the error and the reference message. If a message is indeed an error, the error signifies a problem getting either the hefty message from AWS S3 or an error deserializing the reference message.
func ReferenceMsg ¶
func ReferenceMsg(msgBody string) (*messages.ReferenceMsg, bool)
ReferenceMsg determines if a message body is a reference message and returns a struct representing the reference message. This function is provided to developers who are using workflows where SNS/SQS messages are being sent to endpoints like AWS Lambda where it would be necessary to download the large message from S3 directly without using Hefty. Developers should also perform the necessary cleanup of S3 and SQS when using this workflow.
Types ¶
type Option ¶
type Option func(opts *options) error
func AlwaysSendToS3 ¶
func AlwaysSendToS3() Option
If selected, the message payload will always be sent to AWS S3 regardless of its size
type SnsClientWrapper ¶
func NewSnsClientWrapper ¶
func NewSnsClientWrapper(snsClient *sns.Client, s3Client *s3.Client, bucketName string, opts ...Option) (*SnsClientWrapper, error)
NewSnsClientWrapper will create a new Hefty SNS client wrapper using an existing AWS SNS client and AWS S3 client. This Hefty SNS client wrapper will save large messages greater than MaxSqsSnsMessageLengthBytes to AWS S3 in the bucket that is specified via `bucketName`. The S3 client should have the ability of reading and writing to this bucket. This function will also check if the bucket exists and is accessible.
func (*SnsClientWrapper) PublishHeftyMessage ¶
func (wrapper *SnsClientWrapper) PublishHeftyMessage(ctx context.Context, params *sns.PublishInput, optFns ...func(*sns.Options)) (*sns.PublishOutput, error)
PublishHeftyMessage will calculate the messages size from `params` and determine if the MaxSqsSnsMessageLengthBytes is exceeded. If so, the message is saved in AWS S3 as a hefty message and a reference message is sent to AWS SNS instead. If not, the message is directly sent to AWS SNS.
In the case of the reference message being sent, the message itself contains metadata about the hefty message saved in AWS S3 including bucket name, S3 key, region, and md5 digests. Subscriptions to the AWS SNS topic used in this method should use 'Raw Message Delivery' as an option. This ensures that the hefty client can receive messages from these AWS SQS endpoints. Other endpoints like AWS Lambda can use the reference message directly and download the S3 message without using the hefty client.
Note that this function's signature matches that of the AWS SNS SDK's Publish method.
type SqsClientWrapper ¶
func NewSqsClientWrapper ¶
func NewSqsClientWrapper(sqsClient *sqs.Client, s3Client *s3.Client, bucketName string, opts ...Option) (*SqsClientWrapper, error)
NewSqsClientWrapper will create a new Hefty SQS client wrapper using an existing AWS SQS client and AWS S3 client. This Hefty SQS client wrapper will save large messages greater than MaxSqsSnsMessageLengthBytes to AWS S3 in the bucket that is specified via `bucketName`. The S3 client should have the ability of reading and writing to this bucket. This function will also check if the bucket exists and is accessible.
func (*SqsClientWrapper) DeleteHeftyMessage ¶
func (wrapper *SqsClientWrapper) DeleteHeftyMessage(ctx context.Context, params *sqs.DeleteMessageInput, optFns ...func(*sqs.Options)) (*sqs.DeleteMessageOutput, error)
DeleteHeftyMessage will delete a hefty message from AWS S3 and also the reference message from AWS SQS. It is important to use the `ReceiptHandle` from `ReceiveHeftyMessage` in this function as this is the only way to determine if a hefty message resides in AWS S3 or not.
Note that this function's signature matches that of the AWS SQS SDK's DeleteMessage function.
func (*SqsClientWrapper) ReceiveHeftyMessage ¶
func (wrapper *SqsClientWrapper) ReceiveHeftyMessage(ctx context.Context, params *sqs.ReceiveMessageInput, optFns ...func(*sqs.Options)) (*sqs.ReceiveMessageOutput, error)
ReceiveHeftyMessage will determine if a message received is a reference to a hefty message residing in AWS S3. This method will then download the hefty message and then place its body and message attributes in the returned ReceiveMessageOutput. No modification of messages are made when the message has gone through AWS SQS. It is important to use this function when `SendHeftyMessage` is used so that hefty messages can be downloaded from S3.
Note that this function's signature matches that of the AWS SQS SDK's ReceiveMessage function.
func (*SqsClientWrapper) SendHeftyMessage ¶
func (wrapper *SqsClientWrapper) SendHeftyMessage(ctx context.Context, params *sqs.SendMessageInput, optFns ...func(*sqs.Options)) (*sqs.SendMessageOutput, error)
SendHeftyMessage will calculate the messages size from `params` and determine if the MaxSqsSnsMessageLengthBytes is exceeded. If so, the message is saved in AWS S3 as a hefty message and a reference message is sent to AWS SQS instead. If not, the message is directly sent to AWS SNS.
In the case of the reference message being sent, the message itself contains metadata about the hefty message saved in AWS S3 including bucket name, S3 key, region, and md5 digests.
Note that this function's signature matches that of the AWS SQS SDK's SendMessage function.
func (*SqsClientWrapper) SendHeftyMessageBatch ¶
func (wrapper *SqsClientWrapper) SendHeftyMessageBatch(ctx context.Context, params *sqs.SendMessageBatchInput, optFns ...func(*sqs.Options)) (*sqs.SendMessageBatchOutput, error)
SendHeftyMessageBatch is currently not supported and will use the underlying AWS SQS SDK's method `SendMessageBatch`