Last active
July 3, 2019 22:24
-
-
Save hectorgool/064922546f5e4f7d7ed8845bba84748b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
version: '2' | |
networks: | |
app-tier: | |
driver: bridge | |
services: | |
zookeeper: | |
image: 'bitnami/zookeeper:latest' | |
ports: | |
- '2181:2181' | |
environment: | |
- ALLOW_ANONYMOUS_LOGIN=yes | |
networks: | |
- app-tier | |
kafka: | |
image: 'bitnami/kafka:latest' | |
ports: | |
- '9092:9092' | |
environment: | |
- KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181 | |
- ALLOW_PLAINTEXT_LISTENER=yes | |
networks: | |
- app-tier |
This file contains hidden or 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
# docker-compose build | |
version: "2" | |
services: | |
image: | |
build: . | |
#ports: | |
# - "8080:8080" | |
volumes: | |
- ./:/go/src/github.com/hectorgool/go-docker-kafka-consumer | |
command: bash |
This file contains hidden or 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
# Dockerfile References: https://docs.docker.com/engine/reference/builder/ | |
# Start from golang v1.11 base image | |
FROM golang:1.11 | |
#RUN apk add git | |
# Add Maintainer Info | |
LABEL maintainer="Santo <[email protected]>" | |
#ENV GO111MODULE=on | |
# Agregamos un usuario | |
RUN useradd --user-group --create-home --shell /bin/false app | |
ENV HOME=/go/src/github.com/hectorgool/go-docker-kafka-consumer | |
RUN mkdir -p $HOME | |
WORKDIR $HOME |
This file contains hidden or 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 ( | |
"log" | |
sarama "gopkg.in/Shopify/sarama.v1" | |
) | |
func main() { | |
println("ok 0") | |
consumer, err := sarama.NewConsumer([]string{"kafka:9092"}, nil) | |
if err != nil { | |
panic(err) | |
} | |
println("ok1") | |
defer consumer.Close() | |
partitionConsumer, err := consumer.ConsumePartition("example", 0, sarama.OffsetNewest) | |
if err != nil { | |
panic(err) | |
} | |
println("ok2") | |
defer partitionConsumer.Close() | |
println("ok3") | |
for { | |
msg := <-partitionConsumer.Messages() | |
log.Printf("Consumed message: \"%s\" at offset: %d\n", msg.Value, msg.Offset) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment