Last active
April 13, 2017 20:51
-
-
Save jsokel/176a026d013d3533f8faff849d7dea12 to your computer and use it in GitHub Desktop.
Snippet of GO SQS processor
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
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