-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from lovoo/readme-update
Readme update
- Loading branch information
Showing
3 changed files
with
200 additions
and
128 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Makefile to get Zookeeper and Kafka up and running | ||
|
||
ifdef DOCKER_HOST | ||
DOCKER_IP=$(shell docker-machine ip) | ||
else | ||
DOCKER_IP=127.0.0.1 | ||
endif | ||
|
||
all: | ||
@echo targets: start restart stop | ||
|
||
# delete all images and restart | ||
restart: stop start | ||
@echo done | ||
|
||
# start all images | ||
start: run-zk run-kafka | ||
@echo done | ||
|
||
# stop all images (forces deletion of images) | ||
stop: | ||
@echo stopping Kafka and Zookeeper | ||
@docker rm -f zookeeper kafka | ||
|
||
run-zk: | ||
@echo starting Zookeeper... | ||
@docker run -d -t --name zookeeper \ | ||
-p 2181:2181 \ | ||
wurstmeister/zookeeper | ||
|
||
run-kafka: | ||
@echo starting Kafka... | ||
@docker run -d -t --name kafka \ | ||
-e HOST_IP=kafka \ | ||
-e KAFKA_ADVERTISED_HOST_NAME=${DOCKER_IP} \ | ||
-e KAFKA_ADVERTISED_PORT=9092 \ | ||
-e KAFKA_NUM_PARTITIONS=10 \ | ||
-e KAFKA_DEFAULT_REPLICATION_FACTOR=1 \ | ||
-e KAFKA_REPLICATION_FACTOR=1 \ | ||
-p ${DOCKER_IP}:9092:9092 \ | ||
-p ${DOCKER_IP}:9997:9997 \ | ||
-e KAFKA_BROKER_ID=1 \ | ||
-e ZK=zk -p 9092 \ | ||
--link zookeeper:zk \ | ||
wurstmeister/kafka:0.10.1.0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
"github.com/lovoo/goka" | ||
"github.com/lovoo/goka/codec" | ||
) | ||
|
||
var ( | ||
brokers = []string{"localhost:9092"} | ||
topic goka.Stream = "example-stream" | ||
group goka.Group = "example-group" | ||
) | ||
|
||
// emits a single message and leave | ||
func runEmitter() { | ||
emitter, err := goka.NewEmitter(brokers, topic, new(codec.String)) | ||
if err != nil { | ||
log.Fatalf("error creating emitter: %v", err) | ||
} | ||
defer emitter.Finish() | ||
err = emitter.EmitSync("some-key", "some-value") | ||
if err != nil { | ||
log.Fatalf("error emitting message: %v", err) | ||
} | ||
fmt.Println("message emitted") | ||
} | ||
|
||
// process messages until ctrl-c is pressed | ||
func runProcessor() { | ||
// process callback is invoked for each message delivered from | ||
// "example-stream" topic. | ||
cb := func(ctx goka.Context, msg interface{}) { | ||
var counter int64 | ||
// ctx.Value() gets from the group table the value that is stored for | ||
// the message's key. | ||
if val := ctx.Value(); val != nil { | ||
counter = val.(int64) | ||
} | ||
counter++ | ||
// SetValue stores the incremented counter in the group table for in | ||
// the message's key. | ||
ctx.SetValue(counter) | ||
log.Printf("key = %s, counter = %v, msg = %v", ctx.Key(), counter, msg) | ||
} | ||
|
||
// Define a new processor group. The group defines all inputs, outputs, and | ||
// serialization formats. The group-table topic is "example-group-state". | ||
g := goka.DefineGroup(group, | ||
goka.Input(topic, new(codec.String), cb), | ||
goka.Persist(new(codec.Int64)), | ||
) | ||
|
||
p, err := goka.NewProcessor(brokers, g) | ||
if err != nil { | ||
log.Fatalf("error creating processor: %v", err) | ||
} | ||
go func() { | ||
if err = p.Start(); err != nil { | ||
log.Fatalf("error running processor: %v", err) | ||
} | ||
}() | ||
|
||
wait := make(chan os.Signal, 1) | ||
signal.Notify(wait, syscall.SIGINT, syscall.SIGTERM) | ||
<-wait // wait for SIGINT/SIGTERM | ||
p.Stop() // gracefully stop processor | ||
} | ||
|
||
func main() { | ||
runEmitter() // emits one message and stops | ||
runProcessor() // press ctrl-c to stop | ||
} |