Documentation
¶
Index ¶
- Constants
- Variables
- func ExponentialBackoff(retryCount, minBackoff, maxBackof, backoffFactor int64) int64
- func LinearBackoff(retryCount, minBackoff, maxBackof, backoffFactor int64) int64
- type Client
- func (c *Client) Backoff(queueName *string, message *sqs.Message) error
- func (c *Client) ChangeMessageVisibility(queueName *string, message *sqs.Message, timeout int64) error
- func (c *Client) DeleteMessage(queueName *string, receiptHandle *string) error
- func (c *Client) ReceiveMessages(queueName *string) ([]*sqs.Message, error)
- func (c *Client) ReceiveSQSEvent(event *events.SQSEvent) (*events.SQSEvent, error)
- func (c *Client) SendMessage(queueName *string, payload []byte) error
- func (c *Client) SendMessageWithAttributes(queueName *string, payload []byte, ...) error
- type ClientOption
- func AttributeNames(s ...string) ClientOption
- func BackoffFactor(b int64) ClientOption
- func BackoffFunction(f func(int64, int64, int64, int64) int64) ClientOption
- func CompressionEnabled(b bool) ClientOption
- func DelaySeconds(d int64) ClientOption
- func ForceS3(b bool) ClientOption
- func InitialVisibilityTimeout(i int64) ClientOption
- func KMSKeyCacheEnabled(b bool) ClientOption
- func KMSKeyCacheExpirationPeriod(t time.Duration) ClientOption
- func KMSKeyID(s string) ClientOption
- func MaxNumberOfMessages(m int64) ClientOption
- func MaxVisibilityTimeout(m int64) ClientOption
- func MessageAttributeNames(s ...string) ClientOption
- func S3Bucket(s string) ClientOption
- func SkipSQSClient(b bool) ClientOption
- func WaitTimeSeconds(w int64) ClientOption
Constants ¶
const ( // AttributeNameS3Bucket is an attribute name used by sender to pass the location of messages put on S3 to the receiver. // Receiver uses this attribute if set to fetch a message from S3. AttributeNameS3Bucket = "payloadBucket" // AttributeNameKMSKey used to pass the KMS key used to encryptData the data key. AttributeNameKMSKey = "kmsKey" // AttributeCompression is used to signal that the payload is compressed AttributeCompression = "compression" )
Variables ¶
var ErrorMaxMessageSizeExceeded = fmt.Errorf("maximum message size of %d bytes exceeded", maxMessageSize)
ErrorMaxMessageSizeExceeded is returned when the combined size of the payload and the message attributes exceeds maxMessageSize.
var ErrorMaxNumberOfAttributesExceeded = fmt.Errorf("maximum number of attributes of %d exceeded", maxNumberOfAttributes)
ErrorMaxNumberOfAttributesExceeded is returned when the number of attributes exceeds maxNumberOfAttributes.
Functions ¶
func ExponentialBackoff ¶
ExponentialBackoff can be configured on a client to achieve an exponential backoff strategy based on how many times the message is received.
func LinearBackoff ¶
LinearBackoff can be configured on a awsSQSClient to achieve a linear backoff strategy based on how many times a message is received.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client object handles communication with SQS
func New ¶
func New(awsSession *session.Session, opt ...ClientOption) (*Client, error)
New returns a new awsSQSClient with configuration set as defined by the ClientOptions. Will create a s3Client from the aws.Config if a bucket is set. Same goes for KMS.
func (*Client) Backoff ¶
Backoff is used for changing message visibility based on a calculated amount of time determined by a back off function configured on the awsSQSClient.
func (*Client) ChangeMessageVisibility ¶
func (c *Client) ChangeMessageVisibility(queueName *string, message *sqs.Message, timeout int64) error
ChangeMessageVisibility changes the visibilty of a message. Essentially putting it back in the queue and unavailable for a specified amount of time.
func (*Client) DeleteMessage ¶
DeleteMessage removes a message from the queue.
func (*Client) ReceiveMessages ¶
ReceiveMessages polls the specified queue and returns the fetched messages. If the S3 bucket attribute is set, the payload is fetched and replaces the file event in the sqs.Message body. This will not delete the object in S3. A lifecycle rule is recommended.
func (*Client) ReceiveSQSEvent ¶
ReceiveSQSEvent unpacks payloads in a Lambda SQSEvent if compressed, encrypted or uploaded to S3 by the sennder.
func (*Client) SendMessage ¶
SendMessage sends a message to the specified queue. Convenient method for sending a message without custom attributes. This does not guarantee there will be no attributes on the message to SQS. The client might add attributes eg. for file events when the payload is uploaded to S3.
func (*Client) SendMessageWithAttributes ¶
func (c *Client) SendMessageWithAttributes(queueName *string, payload []byte, messageAttributes map[string]*sqs.MessageAttributeValue) error
SendMessageWithAttributes sends a message to the specified queue with attributes. If the message size exceeds maximum, the payload will be uploaded to the configured S3 bucket and a file event will be sent on the SQS queue. The bucket where the message was uploaded if put on the message attributes. This means an no of attributes error can be thrown even though this function is called with less than maximum number of attributes.
type ClientOption ¶
type ClientOption func(*options)
ClientOption sets configuration options for a awsSQSClient.
func AttributeNames ¶
func AttributeNames(s ...string) ClientOption
AttributeNames sets the attributes to be returned when fetching messages. ApproximateReceiveCount is always returned because it is used when calculating backoff.
func BackoffFactor ¶
func BackoffFactor(b int64) ClientOption
BackoffFactor sets the backoff factor which is a parameter used by the backoff function.
func BackoffFunction ¶
BackoffFunction sets the function which computes the next visibility timeout.
func CompressionEnabled ¶
func CompressionEnabled(b bool) ClientOption
CompressionEnabled is used to enable or disable compression of payload.
func DelaySeconds ¶
func DelaySeconds(d int64) ClientOption
DelaySeconds is used to set the DelaySeconds property on the awsSQSClient which is how many seconds the message will be unavaible once its put on a queue.
func InitialVisibilityTimeout ¶
func InitialVisibilityTimeout(i int64) ClientOption
InitialVisibilityTimeout sets the initial time used when changing message visibility. The length of subsequent changes will be determined by strategy defined by the backoff function used.
func KMSKeyCacheEnabled ¶
func KMSKeyCacheEnabled(b bool) ClientOption
KMSKeyCacheEnabled used to enable or disable kms key caching. Note that caching is against best practise, but might provide significant savings by reducing calls to KMS.
func KMSKeyCacheExpirationPeriod ¶
func KMSKeyCacheExpirationPeriod(t time.Duration) ClientOption
KMSKeyCacheExpirationPeriod sets the amount of time an entry in the kms key cache will be valid.
func KMSKeyID ¶
func KMSKeyID(s string) ClientOption
KMSKeyID sets the KMS key to be used for encryption.
func MaxNumberOfMessages ¶
func MaxNumberOfMessages(m int64) ClientOption
MaxNumberOfMessages sets the maximum number of messages can be returned each time the awsSQSClient fetches messages.
func MaxVisibilityTimeout ¶
func MaxVisibilityTimeout(m int64) ClientOption
MaxVisibilityTimeout sets the maxiumum time a message can be made unavailable by chaning message visibility.
func MessageAttributeNames ¶
func MessageAttributeNames(s ...string) ClientOption
MessageAttributeNames sets the message attributes to be returned when fetching messages. ApproximateReceiveCount is always returned because it is used when calculating backoff.
func S3Bucket ¶
func S3Bucket(s string) ClientOption
S3Bucket sets the bucket where the client should put messages which exceed max size.
func SkipSQSClient ¶
func SkipSQSClient(b bool) ClientOption
SkipSQSClient can be used to skip creation of the SQS client. This is can be used in Lambdas with SQS trigger where handling SQS is not needed, but fetching from S3 and decrypting with KMS is.
func WaitTimeSeconds ¶
func WaitTimeSeconds(w int64) ClientOption
WaitTimeSeconds sets the time a client will wait for messages on each call.