Documentation ¶
Overview ¶
Package listener provides a way of listening to messages published to an AWS SNS Topic.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Consumer ¶
type Consumer interface { // OnMessage is called when a message is successfully processed from the SQS queue. If no messages are processed then OnMessage won't // be called. OnMessage(ctx context.Context, msg MessageContent) }
A Consumer is used by ListenToTopic to process messages and errors during the course of oeprations. Both of its methods are provided with the existing context used by the package so that any implementing type is able to be propagate traces or be made aware of context cancellations.
type Listener ¶ added in v0.7.0
type Listener struct { // PollingInterval is the time between attempts to receive messages from the SQS queue PollingInterval time.Duration // QueueName is the desired name for the SQS queue. If blank a v4 UUID prefixed with "sns-listener" will be used QueueName string // TopicArn is the ARN of the SNS topic to be listened to. TopicArn string // Verbose will enable logging to stderr when true, otherwise logs are discarded Verbose bool // SnsClient is a user-provided client used to interact with the SNS API SnsClient SNSAPI // SqsClient is a user-provided client used to interact with the SQS API SqsClient SQSAPI // contains filtered or unexported fields }
A Listener manages the resources for listening to a queue. It should not be instantiated directly, instead the New() function should be used.
func (*Listener) Listen ¶ added in v0.7.0
Listen is a blocking function that processes messages from the SQS queue as they arrive. Listen will block until the context provided to it is cancelled. Messages will be passed to the provided Consumer's OnMessage method then deleted from the queue. Do not pass the same context as provided to Teardown otherwise resources will not be destroyed.
type MessageContent ¶
A MessageContent maps the message body and message ID of a SQS message to a much more straightforward struct. For the purpose of listening to an SNS topic, the Body contains the full message that was published
type Option ¶ added in v0.7.0
type Option func(l *Listener)
An Option allows for the passing of optional parameters when creating a new Listener.
func WithPollingInterval ¶ added in v0.7.0
WithPollingInterval will set PollingInterval to the provided time. Defaults to 1 second if set to 0.
func WithQueueName ¶ added in v0.7.0
WithQueueName will control the name of the SQS queue created by the Listener. When listening to a FIFO topic, the Listener will add ".fifo" to the queue itself.
func WithVerbose ¶ added in v0.7.0
WithVerbose controls whether or not logs will be printed to stderr.
type SNSAPI ¶
type SNSAPI interface { Subscribe(ctx context.Context, params *sns.SubscribeInput, optFns ...func(*sns.Options)) (*sns.SubscribeOutput, error) Unsubscribe(ctx context.Context, params *sns.UnsubscribeInput, optFns ...func(*sns.Options)) (*sns.UnsubscribeOutput, error) }
SNSAPI is a shim over v2 of the AWS SDK's sns client. The sns client provided by github.com/aws/aws-sdk-go-v2/service/sns automatically satisfies this.
type SQSAPI ¶
type SQSAPI interface { CreateQueue(ctx context.Context, params *sqs.CreateQueueInput, optFns ...func(*sqs.Options)) (*sqs.CreateQueueOutput, error) DeleteQueue(ctx context.Context, params *sqs.DeleteQueueInput, optFns ...func(*sqs.Options)) (*sqs.DeleteQueueOutput, error) GetQueueAttributes(ctx context.Context, params *sqs.GetQueueAttributesInput, optFns ...func(*sqs.Options)) (*sqs.GetQueueAttributesOutput, error) ReceiveMessage(ctx context.Context, params *sqs.ReceiveMessageInput, optFns ...func(*sqs.Options)) (*sqs.ReceiveMessageOutput, error) DeleteMessage(ctx context.Context, params *sqs.DeleteMessageInput, optFns ...func(*sqs.Options)) (*sqs.DeleteMessageOutput, error) }
SQSAPI is a shim over v2 of the AWS SDK's sqs client. The sqs client provided by github.com/aws/aws-sdk-go-v2/service/sqs automatically satisfies this.