Skip to content

Instantly share code, notes, and snippets.

@jsokel
Last active April 13, 2017 20:51
Show Gist options
  • Save jsokel/176a026d013d3533f8faff849d7dea12 to your computer and use it in GitHub Desktop.
Save jsokel/176a026d013d3533f8faff849d7dea12 to your computer and use it in GitHub Desktop.
Snippet of GO SQS processor
func (t *Tasks) consumerLoop() {
ConsumerLoop:
for {
select {
case msg := <-t.consumer.MessageChan():
t.processMessage(msg)
case <-t.closer.NotifyChan():
break ConsumerLoop
}
}
}
func (t *Tasks) processMessage(msg *sqs.Message) {
log.Debugf("Process Message: %s", *msg.MessageId)
msgTypeAttr, ok := msg.MessageAttributes[queue.MsgTypeKey]
if !ok {
log.Errorf("Type attribute not found, message ignored")
t.consumer.Delete(msg)
return
}
msgType := *msgTypeAttr.StringValue
processor, ok := t.processors[msgType]
if !ok {
log.Errorf("Message ignored, invalid task type: %s", msgType)
t.consumer.Delete(msg)
return
}
processor.Process(msg)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment