Skip to content

Commit

Permalink
Added Additional example and updated the readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Whitcraft committed Jan 28, 2017
1 parent 73b613e commit 2788801
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 29 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# sqs-queue
GoLang SQS Queue Worker using the AWS SDK
# go-sqs-poller

This is based off of [golang-sqs-worker-example](https://github.com/nabeken/golang-sqs-worker-example) but it uses the [official AWS golang SDK](https://github.com/aws/aws-sdk-go).
GoLang SQS Queue Poller using the AWS SDK

When running this make sure that you specify `AWS_SDK_LOAD_CONFIG=true` before running. It will pick up credentials from the `~/.aws/config` file.
This is based off of [golang-sqs-worker-example](https://github.com/nabeken/golang-sqs-worker-example) but it uses the [official AWS golang SDK](https://github.com/aws/aws-sdk-go).

### To Do
- Add support for passing in access keys when creating the sqs service instead of auto loading them.
Check out the [cmd/example-worker](cmd/example-worker) directory for examples of how to use the worker.
25 changes: 25 additions & 0 deletions cmd/example-worker/keys_from_environment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

import (
"fmt"

"github.com/aws/aws-sdk-go/service/sqs"
"github.com/aws/aws-sdk-go/aws"

"github.com/jwhitcraft/sqs-queue/worker"
)

func main() {
// Make sure that AWS_SDK_LOAD_CONFIG=true is defined as an environment variable before running the application
// like this

// create the new client and return the url
svc, url := worker.NewSQSClient("go-webhook-queue-test")
// set the queue url
worker.QueueURL = url
// start the worker
worker.Start(svc, worker.HandlerFunc(func (msg *sqs.Message) error {
fmt.Println(aws.StringValue(msg.Body))
return nil
}))
}
36 changes: 36 additions & 0 deletions cmd/example-worker/keys_from_variables.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import (
"fmt"

"github.com/aws/aws-sdk-go/service/sqs"
"github.com/aws/aws-sdk-go/aws"

"github.com/jwhitcraft/sqs-queue/worker"
"github.com/aws/aws-sdk-go/aws/credentials"
)

var (
aws_access_key string
aws_secret_key string
aws_region string
)

func main() {

// create a config
aws_config := &aws.Config{
Credentials: credentials.NewStaticCredentials(aws_access_key, aws_secret_key, ""),
Region: aws.String(aws_region),
}

// create the new client with the aws_config passed in
svc, url := worker.NewSQSClient("go-webhook-queue-test", aws_config)
// set the queue url
worker.QueueURL = url
// start the worker
worker.Start(svc, worker.HandlerFunc(func(msg *sqs.Message) error {
fmt.Println(aws.StringValue(msg.Body))
return nil
}))
}
23 changes: 0 additions & 23 deletions cmd/example-worker/main.go

This file was deleted.

0 comments on commit 2788801

Please sign in to comment.