Setup, um `grundlagen/simple-consumer` als Consumer Group zu skalieren grundlagen/simple-consumer--consumergroup--vorlage grundlagen/simple-consumer--consumergroup--vorlage--2025-03-18--19-42 grundlagen/simple-consumer--consumergroup--vorlage--2025-03-signal grundlagen/simple-consumer--consumergroup--vorlage--2025-04-signal
authorKai Moritz <kai@juplo.de>
Tue, 29 Oct 2024 13:05:40 +0000 (14:05 +0100)
committerKai Moritz <kai@juplo.de>
Fri, 14 Mar 2025 15:51:26 +0000 (16:51 +0100)
.dockerignore [deleted file]
.maven-dockerexclude [deleted file]
.maven-dockerinclude [deleted file]
Dockerfile [deleted file]
build.gradle [deleted file]
docker/docker-compose.yml
pom.xml [deleted file]
settings.gradle [deleted file]
src/main/java/de/juplo/kafka/ExampleConsumer.java [deleted file]
src/main/resources/logback.xml [deleted file]

diff --git a/.dockerignore b/.dockerignore
deleted file mode 100644 (file)
index 9127d15..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-*
-!Dockerfile
-!target/*.jar
-!target/libs/*.jar
diff --git a/.maven-dockerexclude b/.maven-dockerexclude
deleted file mode 100644 (file)
index 72e8ffc..0000000
+++ /dev/null
@@ -1 +0,0 @@
-*
diff --git a/.maven-dockerinclude b/.maven-dockerinclude
deleted file mode 100644 (file)
index a00c65f..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-target/*.jar
-target/libs/*.jar
diff --git a/Dockerfile b/Dockerfile
deleted file mode 100644 (file)
index 22819af..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-FROM eclipse-temurin:21-jre
-VOLUME /tmp
-COPY target/*.jar /opt/app.jar
-COPY target/libs /opt/libs
-ENTRYPOINT [ "java", "-jar", "/opt/app.jar" ]
-CMD [ "kafka:9092", "test", "my-group", "DCKR" ]
diff --git a/build.gradle b/build.gradle
deleted file mode 100644 (file)
index be0bc47..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
-
-plugins {
-       id 'java'
-       id 'org.springframework.boot' version '3.4.1'
-       id 'io.spring.dependency-management' version '1.1.7'
-       id 'com.bmuschko.docker-remote-api' version '9.3.3'
-}
-
-group = 'de.juplo.kafka'
-version = '1.0-SNAPSHOT'
-
-java {
-       toolchain {
-               languageVersion = JavaLanguageVersion.of(21)
-       }
-}
-
-configurations {
-       compileOnly {
-               extendsFrom annotationProcessor
-       }
-}
-
-repositories {
-       mavenCentral()
-}
-
-dependencies {
-       implementation 'org.apache.kafka:kafka-clients'
-       implementation 'ch.qos.logback:logback-classic'
-       compileOnly 'org.projectlombok:lombok'
-       annotationProcessor 'org.projectlombok:lombok'
-}
-
-docker {
-       // Optional: Konfiguriere den Docker-Host, falls nötig
-       // url = 'unix:///var/run/docker.sock' (Standard)
-}
-
-
-def targetDir = file("${projectDir}/target")
-def appJarName = "${project.name}-${project.version}.jar"
-
-// Task zum Bereinigen des `target`-Verzeichnisses bei `clean`
-clean {
-       delete targetDir
-}
-
-// Task zum Kopieren des Haupt-JARs
-task copyJar(type: Copy) {
-       from "$buildDir/libs/${appJarName}"
-       into targetDir
-       dependsOn build
-
-       doFirst {
-               def libs = file("${targetDir}/libs")
-               mkdir(libs)
-       }
-}
-
-// Docker-Task
-task buildDockerImage(type: DockerBuildImage) {
-       inputDir = file('.')
-       images = ["juplo/${project.name}:${project.version}"]
-       dependsOn copyJar
-}
index 9553900..18c8047 100644 (file)
@@ -143,6 +143,14 @@ services:
     image: juplo/simple-consumer:1.0-SNAPSHOT
     command: kafka:9092 test my-group consumer
 
+  peter:
+    image: juplo/simple-consumer:1.0-SNAPSHOT
+    command: kafka:9092 test my-group peter
+
+  ute:
+    image: juplo/simple-consumer:1.0-SNAPSHOT
+    command: kafka:9092 test my-group ute
+
 volumes:
   zookeeper-data:
   zookeeper-log:
diff --git a/pom.xml b/pom.xml
deleted file mode 100644 (file)
index a100717..0000000
--- a/pom.xml
+++ /dev/null
@@ -1,99 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
-
-  <modelVersion>4.0.0</modelVersion>
-
-  <parent>
-    <groupId>org.springframework.boot</groupId>
-    <artifactId>spring-boot-starter-parent</artifactId>
-    <version>3.4.1</version>
-    <relativePath/> <!-- lookup parent from repository -->
-  </parent>
-
-  <groupId>de.juplo.kafka</groupId>
-  <artifactId>simple-consumer</artifactId>
-  <name>Simple Consumer-Group</name>
-  <description>Super Simple Consumer-Group, that is implemented as a plain Java-program</description>
-  <version>1.0-SNAPSHOT</version>
-
-  <properties>
-    <java.version>21</java.version>
-  </properties>
-
-  <dependencies>
-    <dependency>
-      <groupId>org.apache.kafka</groupId>
-      <artifactId>kafka-clients</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.projectlombok</groupId>
-      <artifactId>lombok</artifactId>
-      <scope>compile</scope>
-    </dependency>
-    <dependency>
-      <groupId>ch.qos.logback</groupId>
-      <artifactId>logback-classic</artifactId>
-    </dependency>
-  </dependencies>
-
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-dependency-plugin</artifactId>
-        <executions>
-          <execution>
-            <id>copy-dependencies</id>
-            <phase>package</phase>
-            <goals>
-              <goal>copy-dependencies</goal>
-            </goals>
-            <configuration>
-              <outputDirectory>${project.build.directory}/libs</outputDirectory>
-            </configuration>
-          </execution>
-        </executions>
-      </plugin>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-jar-plugin</artifactId>
-        <configuration>
-          <archive>
-            <manifest>
-              <addClasspath>true</addClasspath>
-              <classpathPrefix>libs/</classpathPrefix>
-              <mainClass>de.juplo.kafka.ExampleConsumer</mainClass>
-            </manifest>
-          </archive>
-        </configuration>
-      </plugin>
-      <plugin>
-        <groupId>pl.project13.maven</groupId>
-        <artifactId>git-commit-id-plugin</artifactId>
-      </plugin>
-      <plugin>
-        <groupId>io.fabric8</groupId>
-        <artifactId>docker-maven-plugin</artifactId>
-        <version>0.45.0</version>
-        <configuration>
-          <images>
-            <image>
-              <name>juplo/%a:%v</name>
-            </image>
-          </images>
-        </configuration>
-        <executions>
-          <execution>
-             <id>build</id>
-             <phase>package</phase>
-             <goals>
-               <goal>build</goal>
-             </goals>
-          </execution>
-        </executions>
-      </plugin>
-    </plugins>
-  </build>
-
-</project>
diff --git a/settings.gradle b/settings.gradle
deleted file mode 100644 (file)
index 71fb573..0000000
+++ /dev/null
@@ -1 +0,0 @@
-rootProject.name = 'simple-consumer'
diff --git a/src/main/java/de/juplo/kafka/ExampleConsumer.java b/src/main/java/de/juplo/kafka/ExampleConsumer.java
deleted file mode 100644 (file)
index 15d72ad..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-package de.juplo.kafka;
-
-import lombok.extern.slf4j.Slf4j;
-import org.apache.kafka.clients.consumer.ConsumerRecord;
-import org.apache.kafka.clients.consumer.ConsumerRecords;
-import org.apache.kafka.clients.consumer.Consumer;
-import org.apache.kafka.clients.consumer.KafkaConsumer;
-import org.apache.kafka.common.errors.WakeupException;
-import org.apache.kafka.common.serialization.StringDeserializer;
-
-import java.time.Duration;
-import java.util.Arrays;
-import java.util.Properties;
-
-
-@Slf4j
-public class ExampleConsumer
-{
-  private final String id;
-  private final String topic;
-  private final Consumer<String, String> consumer;
-
-  private volatile boolean running = false;
-  private long consumed = 0;
-
-  public ExampleConsumer(
-    String broker,
-    String topic,
-    String groupId,
-    String clientId)
-  {
-    Properties props = new Properties();
-    // Konfiguration für den Consumer zusammenstellen
-
-    this.id = clientId;
-    this.topic = topic;
-    consumer = new KafkaConsumer<>(props);
-  }
-
-
-  public void run()
-  {
-    try
-    {
-      log.info("{} - Subscribing to topic {}", id, topic);
-      // TODO: subscribe!
-      running = true;
-
-      while (true)
-      {
-        // TODO:
-        // Über consumer.poll() Nachrichten abrufen und loggen
-      }
-    }
-    catch(WakeupException e)
-    {
-      log.info("{} - Consumer was signaled to finish its work", id);
-    }
-    catch(Exception e)
-    {
-      log.error("{} - Unexpected error, unsubscribing!", id, e);
-    }
-    finally
-    {
-      running = false;
-      log.info("{} - Closing the KafkaConsumer", id);
-      consumer.close();
-      log.info("{}: Consumed {} messages in total, exiting!", id, consumed);
-    }
-  }
-
-
-  public static void main(String[] args) throws Exception
-  {
-    String broker = ":9092";
-    String topic = "test";
-    String groupId = "my-group";
-    String clientId = "DEV";
-
-    switch (args.length)
-    {
-      case 4:
-        clientId = args[3];
-      case 3:
-        groupId = args[2];
-      case 2:
-        topic = args[1];
-      case 1:
-        broker = args[0];
-    }
-
-
-    ExampleConsumer instance = new ExampleConsumer(broker, topic, groupId, clientId);
-
-    Runtime.getRuntime().addShutdownHook(new Thread(() ->
-    {
-      instance.consumer.wakeup();
-
-      while (instance.running)
-      {
-        log.info("Waiting for main-thread...");
-        try
-        {
-          Thread.sleep(1000);
-        }
-        catch (InterruptedException e) {}
-      }
-      log.info("Shutdown completed.");
-    }));
-
-    log.info(
-      "Running ExampleConsumer: broker={}, topic={}, group-id={}, client-id={}",
-      broker,
-      topic,
-      groupId,
-      clientId);
-    instance.run();
-  }
-}
diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml
deleted file mode 100644 (file)
index 7a25e76..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<configuration>
-
-  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
-    <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
-      <Pattern>%d{HH:mm:ss.SSS} | %highlight(%-5level) %msg%n</Pattern>
-    </encoder>
-  </appender>
-
-  <logger name="de.juplo" level="TRACE"/>
-
-  <root level="INFO">
-    <appender-ref ref="STDOUT" />
-  </root>
-
-</configuration>