-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Konstantinos Livieratos
committed
Feb 19, 2021
1 parent
b90c9a9
commit 55f0cf0
Showing
2 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |