Created
August 22, 2016 22:42
-
-
Save 0sc/53060507ab5a6d7bf7d553d0b949e10d to your computer and use it in GitHub Desktop.
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
topic := "topic-to-subscribe-to" //e.g. user-created-topic | |
partitionList := consumer.Partitions(topic) //get all partitions | |
messages := make(chan *sarama.ConsumerMessage, 256) | |
initialOffset := sarama.OffsetOldest //offset to start reading message from | |
for _, partition := range partitionList { | |
pc, _ := consumer.ConsumePartition(topic, partition, initialOffset) | |
go func(pc sarama.PartitionConsumer) { | |
for message := range pc.Messages() { | |
messages <- message //or call a function that writes to disk | |
} | |
}(pc) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment