Skip to content

Commit

Permalink
Added a simple example
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantinos Livieratos committed Feb 19, 2021
1 parent b90c9a9 commit 55f0cf0
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# go-sqs
# go-sqs-worker

This is a simple wrapping library in order to help you onboard easier your Go services with SQS. The idea
is that a service has a consumer and/or a producer of SQS messages. Consider this library some boilerplate
for facilitating this integration.

# Example

See a simple usage example [here](example/simple.go).
55 changes: 55 additions & 0 deletions example/simple.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package main

import (
"fmt"
"log"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/sqs"
sqsworker "github.com/koslib/go-sqs-worker"
)

var (
sqsJobUrl string
)

func main() {
sqsJobUrl = "add your SQS url here"

awsSession := session.Must(session.NewSession(&aws.Config{
Region: aws.String("us-east-1"),
}))
sqsQueue := sqs.New(awsSession)

publisher := sqsworker.NewPublisher(sqsQueue, sqsJobUrl, 10)

payload := "this is a test message body"
err := publisher.PublishMessage(
payload,
map[string]*sqs.MessageAttributeValue{
"Foo": {
DataType: aws.String("String"),
StringValue: aws.String("Bar"),
},
},
)
if err != nil {
log.Println("failed to publish message")
}

listener := sqsworker.NewListener(sqsQueue, sqsJobUrl, 5, 10)
listener.Start(MyMsgHandler{})

}

// MyMsgHandler implements the Handler interface
type MyMsgHandler struct {
// list any dependencies for your handler here
}

// HandleMessage just prints the body of the message received
func (m MyMsgHandler) HandleMessage(msg *sqs.Message) error {
fmt.Println(msg.Body)
return nil
}

0 comments on commit 55f0cf0

Please sign in to comment.