Skip to content

Commit

Permalink
Address PR comments; use mapped port for Kafka.
Browse files Browse the repository at this point in the history
  • Loading branch information
garyrussell committed Jul 28, 2022
1 parent 7c86aa3 commit 550e525
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ bin/
.idea/
out/
ci/pipeline.yml
.DS_Store

4 changes: 3 additions & 1 deletion spring-kafka-avro/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ plugins {
id "com.github.davidmc24.gradle.plugin.avro" version "1.3.0"
}

apply plugin: "com.github.davidmc24.gradle.plugin.avro"
tasks.named("checkFormatMain").configure {
exclude { it.file.absolutePath.contains("generated-main-avro-java") }
}

dependencies {
implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES))
Expand Down
7 changes: 5 additions & 2 deletions spring-kafka-avro/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ services:
image: wurstmeister/kafka
hostname: kafka
ports:
- "9092:9092"
- "9092"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_LISTENERS: PLAINTEXT://:29092,PLAINTEXT_HOST://:9092
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:_{PORT_COMMAND}
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
PORT_COMMAND: "docker ps | grep kafka_1 | cut -d: -f 2 | cut -d- -f 1"
depends_on:
- zookeeper

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,36 +41,28 @@ public Object deserialize(String topic, Headers headers, byte[] data) {
DatumReader<GenericRecord> datumReader;
switch (new String(headers.lastHeader("thing").value())) {
case "Thing1":
datumReader = new SpecificDatumReader<>(
Thing1.class.getDeclaredConstructor().newInstance().getSchema());
datumReader = new SpecificDatumReader<>(new Thing1().getSchema());
break;
case "Thing2":
datumReader = new SpecificDatumReader<>(
Thing2.class.getDeclaredConstructor().newInstance().getSchema());
datumReader = new SpecificDatumReader<>(new Thing2().getSchema());
break;
case "Thing3":
datumReader = new SpecificDatumReader<>(
Thing3.class.getDeclaredConstructor().newInstance().getSchema());
datumReader = new SpecificDatumReader<>(new Thing3().getSchema());
break;
case "Thing4":
datumReader = new SpecificDatumReader<>(
Thing4.class.getDeclaredConstructor().newInstance().getSchema());
datumReader = new SpecificDatumReader<>(new Thing4().getSchema());
break;
case "Thing5":
datumReader = new SpecificDatumReader<>(
Thing5.class.getDeclaredConstructor().newInstance().getSchema());
datumReader = new SpecificDatumReader<>(new Thing5().getSchema());
break;
case "Thing6":
datumReader = new SpecificDatumReader<>(
Thing6.class.getDeclaredConstructor().newInstance().getSchema());
datumReader = new SpecificDatumReader<>(new Thing6().getSchema());
break;
case "Thing7":
datumReader = new SpecificDatumReader<>(
Thing7.class.getDeclaredConstructor().newInstance().getSchema());
datumReader = new SpecificDatumReader<>(new Thing7().getSchema());
break;
case "Thing8":
datumReader = new SpecificDatumReader<>(
Thing8.class.getDeclaredConstructor().newInstance().getSchema());
datumReader = new SpecificDatumReader<>(new Thing8().getSchema());
break;
default:
datumReader = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spring.kafka.bootstrap-servers=localhost:9092
spring.kafka.bootstrap-servers=localhost:${KAFKA_PORT_9092:9092}

spring.kafka.consumer.auto-offset-reset=earliest
spring.kafka.consumer.group-id=graal3
2 changes: 1 addition & 1 deletion spring-kafka-streams/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
dependencies {
implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES))
implementation("org.springframework.boot:spring-boot-starter")
implementation("org.springframework.kafka:spring-kafka:3.0.0-XAOT")
implementation("org.springframework.kafka:spring-kafka:3.0.0-SNAPSHOT")
implementation("org.apache.kafka:kafka-streams")
implementation("com.fasterxml.jackson.core:jackson-databind")

Expand Down
7 changes: 5 additions & 2 deletions spring-kafka-streams/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ services:
image: wurstmeister/kafka
hostname: kafka
ports:
- "9092:9092"
- "9092"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_LISTENERS: PLAINTEXT://:29092,PLAINTEXT_HOST://:9092
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:_{PORT_COMMAND}
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
PORT_COMMAND: "docker ps | grep kafka_1 | cut -d: -f 2 | cut -d- -f 1"
depends_on:
- zookeeper

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
spring.application.name=graalKafkaStreams

spring.kafka.bootstrap-servers=localhost:${KAFKA_PORT_9092:9092}
spring.kafka.consumer.auto-offset-reset=earliest

spring.kafka.streams.properties.default.key.serde=org.apache.kafka.common.serialization.Serdes$StringSerde
Expand Down
7 changes: 5 additions & 2 deletions spring-kafka/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ services:
image: wurstmeister/kafka
hostname: kafka
ports:
- "9092:9092"
- "9092"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_LISTENERS: PLAINTEXT://:29092,PLAINTEXT_HOST://:9092
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:_{PORT_COMMAND}
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
PORT_COMMAND: "docker ps | grep kafka_1 | cut -d: -f 2 | cut -d- -f 1"
depends_on:
- zookeeper

Expand Down
1 change: 1 addition & 0 deletions spring-kafka/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
spring.kafka.bootstrap-servers=localhost:${KAFKA_PORT_9092:9092}
spring.kafka.consumer.auto-offset-reset=earliest
spring.kafka.consumer.value-deserializer=org.springframework.kafka.support.serializer.JsonDeserializer
spring.kafka.consumer.properties[spring.json.trusted.packages]=com.example.kafka
Expand Down

0 comments on commit 550e525

Please sign in to comment.