Skip to content

Instantly share code, notes, and snippets.

@0sc
Created August 22, 2016 22:42
Show Gist options
  • Save 0sc/53060507ab5a6d7bf7d553d0b949e10d to your computer and use it in GitHub Desktop.
Save 0sc/53060507ab5a6d7bf7d553d0b949e10d to your computer and use it in GitHub Desktop.
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