Kafka is a distributed publish-subscribe messaging system: (http://sna-projects.com/kafka/)
Go language: (http://golang.org/)
Install kafka.go package:
make install
Make the tools (publisher & consumer)
make tools
Start zookeeper, Kafka server
For more info on Kafka, see: http://sna-projects.com/kafka/quickstart.php
Start a consumer:
./tools/consumer/consumer -topic test -consumeforever
Consuming Messages :
From: localhost:9092, topic: test, partition: 0
----------------------
Now the consumer will just poll until a message is received.
Publish a message:
./tools/publisher/publisher -topic test -message "Hello World"
The consumer should output message.
broker := kafka.NewBrokerPublisher("localhost:9092", "mytesttopic", 0)
broker.Publish(kafka.NewMessage([]byte("tesing 1 2 3")))
broker := kafka.NewBrokerConsumer("localhost:9092", "mytesttopic", 0, 0, 1048576)
broker.Consume(func(msg *kafka.Message) { msg.Print() })
Or the consumer can use a channel based approach:
broker := kafka.NewBrokerConsumer("localhost:9092", "mytesttopic", 0, 0, 1048576)
go broker.ConsumeOnChannel(msgChan, 10, quitChan)
broker := kafka.NewBrokerOffsetConsumer("localhost:9092", "mytesttopic", 0)
offsets, err := broker.GetOffsets(-1, 1)
jeffreydamick (at) gmail (dot) com
http://twitter.com/jeffreydamick
Big thank you to NeuStar for sponsoring this work.