Skip to content

Commit 13aedba

Browse files
committed
circle ci
1 parent 76bd18b commit 13aedba

File tree

7 files changed

+71
-19
lines changed

7 files changed

+71
-19
lines changed

.circleci/config.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: 2
2+
jobs:
3+
build:
4+
docker:
5+
# specify the version
6+
- image: circleci/golang:1.14
7+
- image: pafortin/goaws
8+
working_directory: /go/src/github.com/qhenkart/gosqs
9+
steps:
10+
- checkout
11+
- run:
12+
name: Install dependencies
13+
command: |
14+
go mod tidy
15+
docker run --rm -v /go/src/github.com/qhenkart/gosqs/emulator/sqsconf.yaml:/sqsconf.yaml -p 4100:4100 pafortin/goaws --config /sqsconf.yaml
16+
- run: go test -v ./...

consumer.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ func NewConsumer(c Config, queueName string) (Consumer, error) {
100100
return cons, nil
101101
}
102102

103+
// Logger accesses the logging field or applies a default logger
104+
func (c *consumer) Logger() Logger {
105+
if c.logger == nil {
106+
return &defaultLogger{}
107+
}
108+
return c.logger
109+
}
110+
103111
// RegisterHandler registers an event listener and an associated handler. If the event matches, the handler will
104112
// be run along with any included middleware
105113
func (c *consumer) RegisterHandler(name string, h Handler, adapters ...Adapter) {
@@ -142,15 +150,15 @@ func (c *consumer) Consume() {
142150
for {
143151
output, err := c.sqs.ReceiveMessage(&sqs.ReceiveMessageInput{QueueUrl: &c.QueueURL, MaxNumberOfMessages: &maxMessages, MessageAttributeNames: []*string{&all}})
144152
if err != nil {
145-
c.logger.Println("%s , retrying in 10s", ErrGetMessage.Context(err).Error())
153+
c.Logger().Println("%s , retrying in 10s", ErrGetMessage.Context(err).Error())
146154
time.Sleep(10 * time.Second)
147155
continue
148156
}
149157

150158
for _, m := range output.Messages {
151159
if _, ok := m.MessageAttributes["route"]; !ok {
152160
//a message will be sent to the DLQ automatically after 4 tries if it is received but not deleted
153-
c.logger.Println(ErrNoRoute.Error())
161+
c.Logger().Println(ErrNoRoute.Error())
154162
continue
155163
}
156164

@@ -163,7 +171,7 @@ func (c *consumer) Consume() {
163171
func (c *consumer) worker(id int, messages <-chan *message) {
164172
for m := range messages {
165173
if err := c.run(m); err != nil {
166-
c.logger.Println(err.Error())
174+
c.Logger().Println(err.Error())
167175
}
168176
}
169177
}
@@ -251,7 +259,7 @@ func (c *consumer) sendDirectMessage(ctx context.Context, input *sqs.SendMessage
251259
func (c *consumer) delete(m *message) error {
252260
_, err := c.sqs.DeleteMessage(&sqs.DeleteMessageInput{QueueUrl: &c.QueueURL, ReceiptHandle: m.ReceiptHandle})
253261
if err != nil {
254-
c.logger.Println(ErrUnableToDelete.Context(err).Error())
262+
c.Logger().Println(ErrUnableToDelete.Context(err).Error())
255263
return ErrUnableToDelete.Context(err)
256264
}
257265
return nil
@@ -263,7 +271,7 @@ func (c *consumer) extend(ctx context.Context, m *message) {
263271
for {
264272
//only allow 1 extensions (Default 1m30s)
265273
if count >= c.extensionLimit {
266-
c.logger.Println(ErrMessageProcessing.Error(), m.Route())
274+
c.Logger().Println(ErrMessageProcessing.Error(), m.Route())
267275
return
268276
}
269277

@@ -279,7 +287,7 @@ func (c *consumer) extend(ctx context.Context, m *message) {
279287
extension = extension + int64(c.VisibilityTimeout)
280288
_, err := c.sqs.ChangeMessageVisibility(&sqs.ChangeMessageVisibilityInput{QueueUrl: &c.QueueURL, ReceiptHandle: m.ReceiptHandle, VisibilityTimeout: &extension})
281289
if err != nil {
282-
c.logger.Println(ErrUnableToExtend.Error(), err.Error())
290+
c.Logger().Println(ErrUnableToExtend.Error(), err.Error())
283291
return
284292
}
285293
}

consumer_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ func getConsumer(t *testing.T) *consumer {
4444
Key: "key",
4545
Secret: "secret",
4646
Env: "dev",
47-
Hostname: "http://localhost:4150",
48-
QueueURL: "http://goaws:4150/queue/dev-post-worker",
47+
Hostname: "http://localhost:4100",
48+
QueueURL: "http://local.goaws:4100/queue/dev-post-worker",
4949
}
5050
sess, err := newSession(conf)
5151
if err != nil {
@@ -71,14 +71,14 @@ func TestNewConsumer(t *testing.T) {
7171
Region: "us-west2",
7272
Key: "key",
7373
Secret: "secret",
74-
Hostname: "http://localhost:4150",
74+
Hostname: "http://localhost:4100",
7575
Env: "dev",
7676
}
7777
c, err := NewConsumer(conf, "post-worker")
7878
if err != nil {
7979
t.Fatalf("error creating consumer, got %v", err)
8080
}
81-
expected := "http://goaws:4150/queue/dev-post-worker"
81+
expected := "http://local.goaws:4100/queue/dev-post-worker"
8282
if c.(*consumer).QueueURL != expected {
8383
t.Fatalf("did not properly apply http result, expected %s, got %s", expected, c.(*consumer).QueueURL)
8484
}

emulator/sqsconf.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Local: # Environment name that can be passed on the
33
Host: goaws # hostname of the goaws system (for docker-compose this is the tag name of the container)
44
# you can now use either 1 port for both sns and sqs or alternatively you can comment out Port and use SqsPort + SnsPort for compatibilyt with
55
# yopa and (fage-sns + face-sqs). If both ways are in the config file on the one "Port" will be used by GoAws
6-
Port: 4150 # port to listen on.
6+
Port: 4100 # port to listen on.
77
Region: local
88
LogMessages: true # Log messages (true/false)
99
LogFile: ./goaws_messages.log # Log filename (for message logging

go.mod

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module github.com/qhenkart/gosqs
2+
3+
go 1.15
4+
5+
require github.com/aws/aws-sdk-go v1.34.13

go.sum

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
github.com/aws/aws-sdk-go v1.34.13 h1:wwNWSUh4FGJxXVOVVNj2lWI8wTe5hK8sGWlK7ziEcgg=
2+
github.com/aws/aws-sdk-go v1.34.13/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
3+
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
4+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5+
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
6+
github.com/jmespath/go-jmespath v0.3.0 h1:OS12ieG61fsCg5+qLJ+SsW9NicxNkg3b25OyT2yCeUc=
7+
github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik=
8+
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
9+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
10+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
11+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
12+
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
13+
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
14+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
15+
golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI=
16+
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
17+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
18+
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
19+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
20+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
21+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
22+
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
23+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

publisher_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ func TestNewPublisher(t *testing.T) {
2323
Region: "us-west-1",
2424
Key: "key",
2525
Secret: "secret",
26-
Hostname: "http://localhost:4150",
27-
TopicARN: "arn:aws:sns:local:000000000000:dev",
26+
Hostname: "http://localhost:4100",
27+
TopicARN: "arn:aws:sns:local:000000000000:todolist-dev",
2828
}
2929
_, err := NewPublisher(conf)
3030
if err != nil {
@@ -38,17 +38,17 @@ func TestNewPublisher(t *testing.T) {
3838
Key: "key",
3939
Secret: "secret",
4040
Env: "dev",
41-
Hostname: "http://localhost:4150",
41+
Hostname: "http://localhost:4100",
4242
AWSAccountID: "000000000000",
43-
TopicPrefix: "pre",
43+
TopicPrefix: "todolist",
4444
}
4545
pub, err := NewPublisher(conf)
4646
if err != nil {
4747
t.Fatalf("error creating publisher, got %v", err)
4848
}
4949
arn := pub.(*publisher).arn
50-
if arn != "arn:aws:sns:local:000000000000:pre-dev" {
51-
t.Errorf("did not properly create the arn name, expected %s, got %s", "arn:aws:sns:local:000000000000:pre-dev", arn)
50+
if arn != "arn:aws:sns:local:000000000000:todolist-dev" {
51+
t.Errorf("did not properly create the arn name, expected %s, got %s", "arn:aws:sns:local:000000000000:todolist-dev", arn)
5252
}
5353
})
5454
}
@@ -78,8 +78,8 @@ func getPublisher(t *testing.T) *publisher {
7878
Key: "key",
7979
Env: "dev",
8080
Secret: "secret",
81-
Hostname: "http://localhost:4150",
82-
TopicARN: "arn:aws:sns:local:000000000000:dev",
81+
Hostname: "http://localhost:4100",
82+
TopicARN: "arn:aws:sns:local:000000000000:todolist-dev",
8383
}
8484

8585
sess, err := newSession(conf)

0 commit comments

Comments
 (0)