From b32f2a3f8c4f2fc558ad60e06baca203bd646dcf Mon Sep 17 00:00:00 2001 From: JoranVanBelle Date: Wed, 18 Dec 2024 15:51:16 +0100 Subject: [PATCH] --wip-- [skip ci] --- docker-compose.yml | 70 +++++++++++++++++++++++++++++----------- src/Kafka/Admin.hs | 3 ++ src/Kafka/Admin/Types.hs | 25 ++++++++++++-- 3 files changed, 78 insertions(+), 20 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 9c79ea9..1f3addc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,24 +1,58 @@ version: "3.8" services: - zookeeper: - image: confluentinc/cp-zookeeper - hostname: zookeeper - ports: - - 2182:2181 - environment: - SERVICE_NAME: zookeeper - ZOOKEEPER_CLIENT_PORT: 2181 - - kafka: - image: confluentinc/cp-kafka:latest - hostname: localhost + # Redpanda cluster + redpanda-1: + image: docker.redpanda.com/redpandadata/redpanda:v23.1.1 + container_name: redpanda-1 + command: + - redpanda + - start + - --smp + - '1' + - --reserve-memory + - 0M + - --overprovisioned + - --node-id + - '1' + - --kafka-addr + - PLAINTEXT://0.0.0.0:29092,OUTSIDE://0.0.0.0:9092 + - --advertise-kafka-addr + - PLAINTEXT://redpanda-1:29092,OUTSIDE://localhost:9092 + - --pandaproxy-addr + - PLAINTEXT://0.0.0.0:28082,OUTSIDE://0.0.0.0:8082 + - --advertise-pandaproxy-addr + - PLAINTEXT://redpanda-1:28082,OUTSIDE://localhost:8082 + - --rpc-addr + - 0.0.0.0:33145 + - --advertise-rpc-addr + - redpanda-1:33145 ports: + # - 8081:8081 + - 8082:8082 - 9092:9092 - links: - - zookeeper:zookeeper + - 9644:9644 + - 28082:28082 + - 29092:29092 + + redpanda-console: + image: docker.redpanda.com/redpandadata/console:v2.2.2 + container_name: redpanda-console + entrypoint: /bin/sh + command: -c "echo \"$$CONSOLE_CONFIG_FILE\" > /tmp/config.yml; /app/console" environment: - KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181" - KAFKA_ADVERTISED_LISTENERS: "PLAINTEXT://$KAFKA_TEST_BROKER:9092" - KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 - KAFKA_CREATE_TOPICS: + CONFIG_FILEPATH: /tmp/config.yml + CONSOLE_CONFIG_FILE: | + kafka: + brokers: ["kafka:9092"] + schemaRegistry: + enabled: false + redpanda: + adminApi: + enabled: false + connect: + enabled: false + ports: + - 8080:8080 + depends_on: + - redpanda-1 diff --git a/src/Kafka/Admin.hs b/src/Kafka/Admin.hs index c21ab37..ae572da 100644 --- a/src/Kafka/Admin.hs +++ b/src/Kafka/Admin.hs @@ -8,6 +8,7 @@ import Kafka.Internal.Setup import Kafka.Types import Kafka.Admin.AdminProperties +import Kafka.Admin.Types data KAdmin = KAdmin { adminKafka :: !Kafka @@ -24,3 +25,5 @@ newKAdmin properties = liftIO $ do Left err -> pure $ Left $ KafkaError err Right kafka -> pure $ Right $ KAdmin (Kafka kafka) kafkaConfig +--- CREATE TOPIC --- + diff --git a/src/Kafka/Admin/Types.hs b/src/Kafka/Admin/Types.hs index bfa8e5f..3b17b69 100644 --- a/src/Kafka/Admin/Types.hs +++ b/src/Kafka/Admin/Types.hs @@ -1,8 +1,29 @@ module Kafka.Admin.Types where +import Data.Map + +import Kafka.Types import Kafka.Internal.Setup data KafkaAdmin = KafkaAdmin { - adminProperties :: !Kafka - , kpKafkaConf :: !KafkaConf + kcKafkaPtr :: !Kafka + , kcKafkaConf :: !KafkaConf } + +instance HasKafka KafkaAdmin where + getKafka = kcKafkaPtr + {-# INLINE getKafka #-} + +instance HasKafkaConf KafkaAdmin where + getKafkaConf = kcKafkaConf + {-# INLINE getKafkaConf #-} + +newtype PartitionsCount = PartitionsCount { unPartitionsCount :: Int } deriving (Show, Eq) +newtype ReplicationFactor = ReplicationFactor { unReplicationFactor :: Int } deriving (Show, Eq) + +data NewTopic = NewTopic { + topicName :: TopicName + , topicPartitions :: PartitionsCount + , topicReplicationFactor :: ReplicationFactor + , topicConfig :: Map String String +} deriving (Show)