Created
December 18, 2014 04:48
-
-
Save tylertreat/52099ae18d250c5b420d 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
package main | |
import ( | |
"fmt" | |
"log" | |
"os" | |
"github.com/Shopify/sarama" | |
) | |
func main() { | |
sarama.Logger = log.New(os.Stdout, "sarama: ", log.Lshortfile) | |
pubClient, err := sarama.NewClient("pub", []string{"192.168.59.103:9092"}, | |
sarama.NewClientConfig()) | |
if err != nil { | |
panic(err) | |
} | |
subClient, err := sarama.NewClient("sub", []string{"192.168.59.103:9092"}, | |
sarama.NewClientConfig()) | |
if err != nil { | |
panic(err) | |
} | |
pub, err := sarama.NewProducer(pubClient, nil) | |
if err != nil { | |
panic(err) | |
} | |
consumerConfig := sarama.NewConsumerConfig() | |
consumerConfig.OffsetMethod = sarama.OffsetMethodNewest // Only read new messages | |
consumerConfig.DefaultFetchSize = 10 * 1024 * 1024 | |
sub, err := sarama.NewConsumer(subClient, "test", 0, "test", consumerConfig) | |
if err != nil { | |
panic(err) | |
} | |
pub.Input() <- &sarama.MessageToSend{Topic: "test", Key: nil, Value: sarama.StringEncoder("testing 123")} | |
event := <-sub.Events() | |
fmt.Println(string(event.Value)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment