Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ApsOps committed May 30, 2017
1 parent ac0a026 commit 9140e20
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,22 @@ func startGohaqd(cmd *cobra.Command, args []string) {
QueueUrl: q.QueueUrl,
WaitTimeSeconds: aws.Int64(20),
}

// Create semaphore channel for passing messages to consumers
sem = make(chan *sqs.Message)

// Start multiple goroutines for consumers base on --parallel flag
for i := 0; i < parallelRequests; i++ {
go startConsumer(q.QueueUrl)
}

// Infinitely poll SQS queue for messages
for {
pollSQS()
}
}

// Receives messages from SQS queue and adds to semaphore channel
func pollSQS() {
resp, err := svc.ReceiveMessage(msgparams)
if err != nil {
Expand All @@ -122,6 +127,8 @@ func pollSQS() {
}
}

// Receives messages from semaphore channel and
// deletes a message from SQS queue is it's consumed successfully
func startConsumer(queueURL *string) {
for msg := range sem {
if sendMessageToURL(*msg.Body) {
Expand All @@ -136,6 +143,7 @@ func startConsumer(queueURL *string) {
}
}

// Sends a POST request to consumption endpoint with the SQS message as body
func sendMessageToURL(msg string) bool {
var resp *http.Response
var err error
Expand Down

0 comments on commit 9140e20

Please sign in to comment.