Skip to content

Commit

Permalink
Create simple Spring Kafka Producer and Consumer
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinav-nath committed Jul 25, 2022
1 parent 1d9bb26 commit 06d7254
Show file tree
Hide file tree
Showing 27 changed files with 1,121 additions and 0 deletions.
54 changes: 54 additions & 0 deletions code/spring-kafka-producer-and-consumer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
version: '3.9'
services:

zookeeper:
image: confluentinc/cp-zookeeper:7.0.1
networks:
- kafka_network
container_name: zookeeper
ports:
- "2181:2181"
- "2888:2888"
- "3888:3888"
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000

kafka:
image: confluentinc/cp-kafka:7.0.1
networks:
- kafka_network
container_name: kafka
ports:
- "9092:9092"
- "29092:29092"
depends_on:
- zookeeper
environment:
- KAFKA_BROKER_ID=1
- KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
- KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1
- KAFKA_ADVERTISED_LISTENERS=LISTENER_EXT:https://localhost:29092,LISTENER_INT:https://kafka:9092
- KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=LISTENER_INT:PLAINTEXT,LISTENER_EXT:PLAINTEXT
- KAFKA_LISTENERS=LISTENER_INT:https://kafka:9092, LISTENER_EXT:https://:29092
- KAFKA_INTER_BROKER_LISTENER_NAME=LISTENER_INT
- KAFKA_AUTO_CREATE_TOPICS_ENABLE=true

kafdrop:
image: obsidiandynamics/kafdrop
networks:
- kafka_network
container_name: kafdrop
restart: "no"
ports:
- "9000:9000"
environment:
KAFKA_BROKERCONNECT: "kafka:9092"
BOOTSTRAP_SERVERS: kafka:9092
JVM_OPTS: "-Xms16M -Xmx48M -Xss180K -XX:-TieredCompilation -XX:+UseStringDeduplication -noverify"
depends_on:
- "kafka"

networks:
kafka_network:
name: kafka_net
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = false
trim_trailing_whitespace = true
max_line_length = 200
tab_width = 4

[*.java]
# don't use wildcard for Java imports
wildcard_import_limit = 999
ij_visual_guides = 120
ij_wrap_on_typing = true
ij_java_binary_operation_sign_on_next_line = true
ij_java_align_multiline_chained_methods = true
ij_java_align_multiline_ternary_operation = true
ij_java_align_multiline_array_initializer_expression = true
ij_java_use_single_class_imports = true
ij_java_class_count_to_use_import_on_demand = 999
ij_java_names_count_to_use_import_on_demand = 999
ij_java_imports_layout = *, |, java.**, |, javax.**, |, io.**, |, org.**, |, lombok.**, |, com.**, |, $*
ij_java_layout_static_imports_separately = true

[*.xml]
indent_size = 4
ij_xml_tab_width = 4

# Shell scripts
[*.{cmd, bat}]
end_of_line = crlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
HELP.md
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
plugins {
id 'org.springframework.boot' version '2.7.2'
id 'io.spring.dependency-management' version '1.0.12.RELEASE'
id 'java'
}

group = 'com.codecafe.kafka'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

configurations {
compileOnly {
extendsFrom annotationProcessor
}
}

repositories {
mavenCentral()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.kafka:spring-kafka'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.kafka:spring-kafka-test'
}

tasks.named('test') {
useJUnitPlatform()
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\:https://services.gradle.org/distributions/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 06d7254

Please sign in to comment.