Code Monkey home page Code Monkey logo

kafka_cluster_example's Introduction

🪲 kafka_cluster_example


项目获取:

$ git clone --depth=1 https://github.com/ErikJiang/kafka_cluster_example.git

项目依赖工具:

支持 make 构建:

$ make

Choose a command run in kafka_cluster_example:

Usage: make [target]

Valid target values are:

vendor                  Auto generate go vendor dir.
up                      Docker compose up for src.
down                    Docker compose down for src.
ps                      Docker compose ps for src.
logs                    Docker compose logs for src.
clean                   Clean up docker images for src.
test                    Apache benchmark test for src.
kafka-up                Docker compose up for kafka services.
kafka-down              Docker compose down for kafka services.
kafka-clean             Clean up log and data files for kafka services.
kafka-test              Check running state of the kafka service.
help                    print this help message and exit.

1. 配置 hosts 域名

使用 ifconfig -a 查看本地IP地址;

配置 /etc/hosts 文件,将域名 kfk1、kfk2、kfk3 映射到当前本地 IP 地址,例如;

# 假设本地IP为: 192.168.0.166
192.168.0.166 kfk1 kfk2 kfk3

2. 构建 Kafka 集群

# docker compose 构建方式:
$ docker-compose -f kafka/docker-compose.yml up -d

# 或使用 make 构建方式:
$ make kafka-up

如若在构建下载过程中,出现等待连接超时,可尝试在 docker 的 daemon.json 中添加注册镜像:

{
    "registry-mirrors":["https://docker.mirrors.ustc.edu.cn"]
}

若构建完成,可使用 kafkacat 检测服务是否正常运行:

# 直接进行检测验证:
$ kafkacat -L -b kfk1:19092

# 或使用 make 方式验证:
$ make kafka-test

3. 构建 Produce & Consume 服务

为 produce 和 consume 生成 vendor 依赖:

$ make vendor

构建 Produce & Consume Docker 服务

# 使用 docker compose 直接构建方式:
$ docker-compose -f src/docker-compose.yml up -d

# 或者使用 make 构建方式:
$ make up

4. 最终测试

使用 ApacheBench 进行并发测试(并发数为10,总计100个请求):

# 直接使用 ab 命令进行测试:
$ ab -n100 -c10 -T application/json -p test/ab_post_test.json http://127.0.0.1:9000/api/v1/data

# 或者使用 make 方式测试:
$ make test

文档详见:Wiki

kafka_cluster_example's People

Contributors

erikjiang avatar

Watchers

 avatar

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.