Giter Club home page Giter Club logo

kafka-for-mac's Introduction

kafka-for-mac

For those who use macOS and docker, it can be quite challenging to get several Confluent Kafka components up and running. Support for Docker on macOS / Windows is not yet available as per Confluent. This repo is an attempt to remove the uncertainty and let people experiment with Confluent Kafka faster. Here are some references for you to understand why this challenging

I can't connect to Kafka on OS X

Note: Important Caveat - Images Not Tested for Docker for Mac or Windows

Networking features in Docker for Mac

Pre-requisites

As of this writing, my local is running

Docker version 17.12.0-ce, build c97c6d6r

Getting Started

This docker-compose file has all the components necessary to bring up single node / single broker Kafka cluster,

  • Zookeeper
  • Kafka Broker
  • Schema Registry
  • Kafka REST Proxy

Bootstrap

docker-compose up -d

You should see some results like this

Creating kafkaformac_kafka_1           ... done
Creating kafkaformac_zookeeper_1       ...
Creating kafkaformac_schema-registry_1 ... done
Creating kafkaformac_schema-registry_1 ...
Creating kafkaformac_kafka-rest_1      ... done

Ensure the processes are running

docker-compose ps

You should see some results like this

            Name                         Command            State                           Ports
--------------------------------------------------------------------------------------------------------------------------
kafkaformac_kafka-rest_1        /etc/confluent/docker/run   Up      0.0.0.0:29080->29080/tcp, 8082/tcp
kafkaformac_kafka_1             /etc/confluent/docker/run   Up      0.0.0.0:29092->29092/tcp, 9092/tcp
kafkaformac_schema-registry_1   /etc/confluent/docker/run   Up      0.0.0.0:29081->29081/tcp, 8081/tcp
kafkaformac_zookeeper_1         /etc/confluent/docker/run   Up      2181/tcp, 2888/tcp, 0.0.0.0:32181->32181/tcp, 3888/tcp

Check the health of zookeeper by monitoring its logs through this command

docker-compose logs zookeeper | grep -i binding

Check if the kafka broker is healthy

docker-compose logs kafka | grep -i started

Similarly inspect logs for schema-registry and kafka-rest

docker-compose logs schema-registry

docker-compose logs kafka-rest

Consuming and Producing using the Kafka clients

  • Add a mapping with your machine ip to docker.for.mac.host.internal to your /etc/hosts file
    • e.g. 10.0.4.162 docker.for.mac.host.internal
    • find your machine ip with ifconfig | grep -e "inet "
    • (!) your machine ip changes if you change network, update the config and restart the container
  • Connect to the kafka cluster via localhost:29092 (bootstrap server)

Publishing and Subscribing using Kafka REST

confluentinc/kafka-rest has full documentation around this, but the validate.sh script allows you to run all the same quickly, go ahead and run it

./validate.sh

You should see the RESTful endpoints invoked in sequence for publishing and subscribing from your Kafka

# Get a list of topics
["_schemas","jsontest"]
# Produce a message with JSON data
{"offsets":[{"partition":0,"offset":6,"error_code":null,"error":null}],"key_schema_id":null,"value_schema_id":null}
# Get info about one topic
{"name":"jsontest","configs":{"file.delete.delay.ms":"60000","segment.ms":"604800000","min.compaction.lag.ms":"0","retention.bytes":"-1","segment.index.bytes":"10485760","cleanup.policy":"delete","follower.replication.throttled.replicas":"","message.timestamp.difference.max.ms":"9223372036854775807","segment.jitter.ms":"0","preallocate":"false","segment.bytes":"1073741824","message.timestamp.type":"CreateTime","message.format.version":"0.11.0-IV2","max.message.bytes":"1000012","unclean.leader.election.enable":"false","retention.ms":"604800000","flush.ms":"9223372036854775807","delete.retention.ms":"86400000","leader.replication.throttled.replicas":"","min.insync.replicas":"1","flush.messages":"9223372036854775807","compression.type":"producer","min.cleanable.dirty.ratio":"0.5","index.interval.bytes":"4096"},"partitions":[{"partition":0,"leader":1,"replicas":[{"broker":1,"leader":true,"in_sync":true}]}]}
# Create a consumer for JSON data, starting at the beginning of the topic's log. The consumer group is called "my_json_consumer" and the instance is "my_consumer_instance\  .
{"instance_id":"my_consumer_instance","base_uri":"http://kr-host:8082/consumers/my_json_consumer/instances/my_consumer_instance"}
# Subscribe the consumer to a topic
No content in response
# Then consume some data from a topic using the base URL in the first response.
[]
# Finally, close the consumer with a DELETE to make it leave the group and clean up its resources.
No content in response

Tear down

docker-compose down

Caveats

  • You really don't want bridge network on your docker compose, while its not well documented on why, its advised so. confluentinc/cp-docker-images

Contributing

Fork this repository, send in a pull request

kafka-for-mac's People

Contributors

santthosh avatar timvlaer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

kafka-for-mac's Issues

Can't access kafka out of docker container with 29092 port

I can start the docker-compose and can use kafka with kafka-rest. when i connect to kafka in a java application which run on my mac with localhost:29092, the java application throw a timeout exception.

i think the kafka in container is not ready to be connected. how to make the kafka ready to be connected ?

Unable to start processes

------------------------------
➜  kafka-for-mac git:(master) docker-compose up -d
Creating network "kafkaformac_default" with the default driver
Creating kafkaformac_zookeeper_1 ... done
Creating kafkaformac_kafka_1     ... done
Creating kafkaformac_schema-registry_1 ... done
Creating kafkaformac_kafka-rest_1      ... done

then I check the ps and

➜  kafka-for-mac git:(master) docker-compose ps


            Name                         Command             State     Ports
----------------------------------------------------------------------------
kafkaformac_kafka-rest_1        /etc/confluent/docker/run   Exit 139
kafkaformac_kafka_1             /etc/confluent/docker/run   Exit 139
kafkaformac_schema-registry_1   /etc/confluent/docker/run   Exit 139
kafkaformac_zookeeper_1         /etc/confluent/docker/run   Exit 139
➜  kafka-for-mac git:(master)

Logs of zookeeper show

➜  kafka-for-mac git:(master) docker-compose logs zookeeper


Attaching to kafkaformac_zookeeper_1
zookeeper_1        |
zookeeper_1        | echo "===> ENV Variables ..."
zookeeper_1        | + echo '===> ENV Variables ...'
zookeeper_1        | env | sort
zookeeper_1        | + env
zookeeper_1        | ===> ENV Variables ...
zookeeper_1        | ALLOW_UNSIGNED=false
zookeeper_1        | COMPONENT=zookeeper
zookeeper_1        | CONFLUENT_DEB_VERSION=1
zookeeper_1        | CONFLUENT_MAJOR_VERSION=4
zookeeper_1        | CONFLUENT_MINOR_VERSION=0
zookeeper_1        | CONFLUENT_MVN_LABEL=
zookeeper_1        | CONFLUENT_PATCH_VERSION=0
zookeeper_1        | CONFLUENT_PLATFORM_LABEL=
zookeeper_1        | CONFLUENT_VERSION=4.0.0
zookeeper_1        | CUB_CLASSPATH=/etc/confluent/docker/docker-utils.jar
zookeeper_1        | HOME=/root
zookeeper_1        | HOSTNAME=f40f67694386
zookeeper_1        | KAFKA_VERSION=1.0.0
zookeeper_1        | LANG=C.UTF-8
zookeeper_1        | PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
zookeeper_1        | PWD=/
zookeeper_1        | PYTHON_PIP_VERSION=8.1.2
zookeeper_1        | PYTHON_VERSION=2.7.9-1
zookeeper_1        | SCALA_VERSION=2.11
zookeeper_1        | SHLVL=1
zookeeper_1        | ZOOKEEPER_CLIENT_PORT=32181
zookeeper_1        | ZOOKEEPER_TICK_TIME=2000
zookeeper_1        | ZULU_OPENJDK_VERSION=8=8.17.0.3
zookeeper_1        | + sort
zookeeper_1        | _=/usr/bin/env
zookeeper_1        |
zookeeper_1        | ===> User
zookeeper_1        | echo "===> User"
zookeeper_1        | + echo '===> User'
zookeeper_1        | id
zookeeper_1        | + id
zookeeper_1        | uid=0(root) gid=0(root) groups=0(root)
zookeeper_1        | ===> Configuring ...
zookeeper_1        |
zookeeper_1        | echo "===> Configuring ..."
zookeeper_1        | + echo '===> Configuring ...'
zookeeper_1        | /etc/confluent/docker/configure
zookeeper_1        | + /etc/confluent/docker/configure
zookeeper_1        |
zookeeper_1        |
zookeeper_1        | dub ensure ZOOKEEPER_CLIENT_PORT
zookeeper_1        | + dub ensure ZOOKEEPER_CLIENT_PORT
zookeeper_1        | /etc/confluent/docker/configure: line 23:    11 Segmentation fault      dub ensure ZOOKEEPER_CLIENT_PORT
➜  kafka-for-mac git:(master)

and kafka

Attaching to kafkaformac_kafka_1
kafka_1            | ===> ENV Variables ...
kafka_1            |
kafka_1            | echo "===> ENV Variables ..."
kafka_1            | + echo '===> ENV Variables ...'
kafka_1            | env | sort
kafka_1            | + env
kafka_1            | + sort
kafka_1            | ALLOW_UNSIGNED=false
kafka_1            | COMPONENT=kafka
kafka_1            | CONFLUENT_DEB_VERSION=1
kafka_1            | CONFLUENT_MAJOR_VERSION=4
kafka_1            | CONFLUENT_MINOR_VERSION=0
kafka_1            | CONFLUENT_MVN_LABEL=
kafka_1            | CONFLUENT_PATCH_VERSION=0
kafka_1            | CONFLUENT_PLATFORM_LABEL=
kafka_1            | CONFLUENT_VERSION=4.0.0
kafka_1            | CUB_CLASSPATH=/etc/confluent/docker/docker-utils.jar
kafka_1            | HOME=/root
kafka_1            | HOSTNAME=kafka-host
kafka_1            | KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://docker.for.mac.host.internal:29092
kafka_1            | KAFKA_AUTO_CREATE_TOPICS_ENABLE=true
kafka_1            | KAFKA_BROKER_ID=1
kafka_1            | KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1
kafka_1            | KAFKA_VERSION=1.0.0
kafka_1            | KAFKA_ZOOKEEPER_CONNECT=zookeeper:32181
kafka_1            | LANG=C.UTF-8
kafka_1            | PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
kafka_1            | PWD=/
kafka_1            | PYTHON_PIP_VERSION=8.1.2
kafka_1            | PYTHON_VERSION=2.7.9-1
kafka_1            | SCALA_VERSION=2.11
kafka_1            | SHLVL=1
kafka_1            | ZULU_OPENJDK_VERSION=8=8.17.0.3
kafka_1            | _=/usr/bin/env
kafka_1            | ===> User
kafka_1            |
kafka_1            | echo "===> User"
kafka_1            | + echo '===> User'
kafka_1            | id
kafka_1            | + id
kafka_1            | uid=0(root) gid=0(root) groups=0(root)
kafka_1            | ===> Configuring ...
kafka_1            |
kafka_1            | echo "===> Configuring ..."
kafka_1            | + echo '===> Configuring ...'
kafka_1            | /etc/confluent/docker/configure
kafka_1            | + /etc/confluent/docker/configure
kafka_1            |
kafka_1            | dub ensure KAFKA_ZOOKEEPER_CONNECT
kafka_1            | + dub ensure KAFKA_ZOOKEEPER_CONNECT
kafka_1            | /etc/confluent/docker/configure: line 22:    11 Segmentation fault      dub ensure KAFKA_ZOOKEEPER_CONNECT
➜  kafka-for-mac git:(master)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.