1 Star 0 Fork 1

skay463/Spring-Boot-Clickhouse-Kafka-Engine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

Spring Boot + Kafka + Clickhouse

This is an example Spring Boot + Apache Kafka + Clickhouse + kafdrop app.

It was made using Spring Boot, Clickhouse, Clickhouse Kafka Engine, Apache Kafka, Apache ZooKeeper, Spring Kafka, Docker, kafdrop and Docker Compose.

Requirements

For building and running the application you need:

Clone

Run the command below to clone the project:

git clone https://github.com/keza/Spring-Boot-Clickhouse-Kafka-Engine.git

Run

Build Docker image:

We are using Docker-Compose to start the containers. Go to the root folder where 'docker-compose.yml' is located and run the below command:

cd clickhouse-client

mvn clean install -DskipTests

cd ..

docker-compose up --build -d

[Optional] You can either open a separate terminal and follow the logs while systems are initializing:

docker-compose logs -f

[Optional] Or check the starting status:

docker-compose ps

Create Event

docker exec -it clickhouse-project_kafka_1 /usr/bin/kafka-console-producer   --broker-list localhost:9092 --topic events

{"type": "post_view","post_id": 50}
{"type": "post_view","post_id": 50}
{"type": "post_view","post_id": 50}

fetch data via clickhouse http interface

curl --location --request GET 'localhost:8090/events/post/http/50'

fetch data via clickhouse-native-jdbc

curl --location --request GET 'localhost:8090/events/post/jdbc/50'

Kafdrop – Kafka Web UI

http://localhost:9005/

Stop

Go to the root folder where is docker-compose.yml.

To stop all containers execute:

docker-compose down

Clickhouse SQL

CREATE TABLE event_queue (
                                type String,
                                post_id Int32
)
    ENGINE = Kafka
        SETTINGS kafka_broker_list = 'kafka:9092',
            kafka_topic_list = 'events',
            kafka_group_name = 'events_consumer_group1',
            kafka_format = 'JSONEachRow',
            kafka_num_consumers = 3,
            kafka_thread_per_consumer = 1;
            
CREATE TABLE events (
                          type String,
                          post_id Int32,
                          _topic String,
                          _offset UInt64,
                          _partition UInt64,
                          _timestamp DateTime
) Engine = MergeTree()
   ORDER BY  (type, post_id)
     PRIMARY KEY (type, post_id);
     
CREATE MATERIALIZED VIEW event_queue_mv TO events AS
SELECT type, post_id, _topic, _offset, _partition, _timestamp
FROM event_queue;

CREATE MATERIALIZED VIEW events_count_mv
    Engine = SummingMergeTree()
        ORDER BY  (type, post_id)
    POPULATE
    AS SELECT
              type,
              post_id,
              count() as count
    FROM events
    GROUP BY (type, post_id);

References

https://programmer.help/blogs/how-to-choose-clickhouse-table-engine.html

https://altinity.com/blog/clickhouse-materialized-views-illuminated-part-1

https://altinity.com/blog/clickhouse-kafka-engine-faq

https://altinity.com/blog/2020/5/21/clickhouse-kafka-engine-tutorial

https://github.com/housepower/ClickHouse-Native-JDBC

https://clickhouse.tech/docs/en/engines/table-engines/integrations/kafka/

空文件

简介

取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/skay463/Spring-Boot-Clickhouse-Kafka-Engine.git
git@gitee.com:skay463/Spring-Boot-Clickhouse-Kafka-Engine.git
skay463
Spring-Boot-Clickhouse-Kafka-Engine
Spring-Boot-Clickhouse-Kafka-Engine
master

搜索帮助