This project is a tool bundle for running a service that interacts with AWS SQS written in go. It comes with an opinionated choice of logger, metrics client, and configuration parsing. The benefits are a simple abstraction around the aws-sdk api for consuming from an SQS or producing to an SQS.
package main
import (
"context"
"fmt"
"time"
"github.com/asecurityteam/runsqs/v4"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/sqs"
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
)
type BasicConsumer struct{}
func (m BasicConsumer) ConsumeMessage(ctx context.Context, message *types.Message) runsqs.SQSMessageConsumerError {
fmt.Println(string(*message.Body))
return nil
}
func (m BasicConsumer) DeadLetter(ctx context.Context, message *types.Message) {
fmt.Println("deadletter")
}
func main() {
// create a new SQS config, and establish a SQS instance to connect to.
// aws new sessions by default reads AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY as environment variables to use
ctx := context.Background()
consumerComponent := runsqs.DefaultSQSQueueConsumerComponent{}
consumerConfig := consumerComponent.Settings()
consumerConfig.QueueURL = "www.aws.com/url/to/queue"
consumerConfig.AWSEndpoint = "www.aws.com"
consumerConfig.QueueRegion = "us-east-1"
consumerConfig.PollInterval = 1 * time.Second
consumer, err := consumerComponent.New(ctx, consumerConfig)
if err != nil {
panic(err.Error())
}
consumer.MessageConsumer = BasicConsumer{}
producerComponent := runsqs.DefaultSQSProducerComponent{}
producerConfig := producerComponent.Settings()
producerConfig.QueueURL = "www.aws.com/url/to/queue"
producerConfig.AWSEndpoint = "www.aws.com"
producerConfig.QueueRegion = "us-east-1"
producer, err := producerComponent.New(ctx, producerConfig)
if err != nil {
panic(err.Error())
}
go producer.ProduceMessage(ctx, &sqs.SendMessageInput{
MessageBody: aws.String("incoming sqs message"),
QueueUrl: aws.String(producer.QueueURL()),
})
// Run the SQS consumer.
if err := consumer.StartConsuming(ctx); err != nil {
panic(err.Error())
}
// expected output:
// "incoming sqs message"
}
This project is in incubation which the interfaces and implementations are subject to change.
We publish a docker image called SDCLI that bundles all of our build dependencies. It is used by the included Makefile to help make building and testing a bit easier. The following actions are available through the Makefile:
-
make dep
Install the project dependencies into a vendor directory
-
make lint
Run our static analysis suite
-
make test
Run unit tests and generate a coverage artifact
-
make integration
Run integration tests and generate a coverage artifact
-
make coverage
Report the combined coverage for unit and integration tests
This project is licensed under Apache 2.0. See LICENSE.txt for details.
Atlassian requires signing a contributor's agreement before we can accept a patch. If you are an individual you can fill out the individual CLA. If you are contributing on behalf of your company then please fill out the corporate CLA.