diff --git a/README.md b/README.md index 7c0e330..2029bf8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -[Kafka Sandbox](https://sauljabin.github.io/kafka-sandbox/) it's a markdown book designed to help you to deploy a kafka sandbox locally. It intends to be a simple way to get started with kafka and +[Kafka Sandbox](https://sauljabin.github.io/kafka-sandbox/) it's a markdown book designed to help you to deploy a kafka sandbox locally. +It intends to be a simple way to get started with kafka and help you on your learning path. It provides you with a wide variety of tools from the kafka ecosystem and a simple way to run them all. It also includes a set of tools and tips to make it easier for you to use kafka. It does not include security since it is not a production system. @@ -9,7 +10,7 @@ You can access it at https://sauljabin.github.io/kafka-sandbox/. ## Developing Commands -> You must to install [rust](https://www.rust-lang.org/tools/install) first. +> You must install [rust](https://www.rust-lang.org/tools/install) first. Install `mdbook`: @@ -28,17 +29,3 @@ Build statics: ```bash mdbook build ``` - -## Using Docker - -Create docker image: - -```bash -docker build -t sauljabin/kafka-sandbox-book:latest -f docker/Dockerfile . -``` - -Running the book ([open it in the web browser](http://localhost)): - -```bash -docker run --name kafka-sandbox-book -d -p 80:80 sauljabin/kafka-sandbox-book:latest -``` diff --git a/kafka-spring-boot/src/main/resources/application.yml b/kafka-spring-boot/src/main/resources/application.yml index f01c0a4..347bcbc 100644 --- a/kafka-spring-boot/src/main/resources/application.yml +++ b/kafka-spring-boot/src/main/resources/application.yml @@ -9,10 +9,10 @@ management: spring: kafka: - topic: kafka-spring-boot.customers + topic: spring.customers consumer: bootstrap-servers: localhost:19092,localhost:29092,localhost:39092 - group-id: kafka-spring-boot.consumer + group-id: spring.consumer auto-offset-reset: earliest key-deserializer: org.apache.kafka.common.serialization.StringDeserializer value-deserializer: org.springframework.kafka.support.serializer.JsonDeserializer diff --git a/md/SUMMARY.md b/md/SUMMARY.md index 35d4141..fce177a 100644 --- a/md/SUMMARY.md +++ b/md/SUMMARY.md @@ -15,6 +15,7 @@ - [Kafka Rest Proxy](kafka-rest-proxy.md) - [Kafka MQTT Proxy](kafka-mqtt-proxy.md) - [Avro Producer and Consumer](avro-producer-and-consumer.md) +- [Spring Boot](spring-boot.md) - [Cleanup](cleanup.md) --- diff --git a/md/avro-producer-and-consumer.md b/md/avro-producer-and-consumer.md index 90ac094..68cd7dd 100644 --- a/md/avro-producer-and-consumer.md +++ b/md/avro-producer-and-consumer.md @@ -49,7 +49,7 @@ for (int i = 0; i < messages; i++) { Supplier supplier = createNewCustomer(); ProducerRecord record = new ProducerRecord<>( topic, - supplier.getId(), + supplier.getId().toString(), supplier ); producer.send( diff --git a/md/spring-boot.md b/md/spring-boot.md new file mode 100644 index 0000000..a0be728 --- /dev/null +++ b/md/spring-boot.md @@ -0,0 +1,51 @@ +# Spring Boot + +Spring Boot + Spring Kafka producer and consumer examples. + +### Other LInks + +- [confluent spring kafka examples](https://www.confluent.io/blog/apache-kafka-spring-boot-application/) +- [spring kafka settings](https://docs.spring.io/spring-kafka/reference/html/) + +### Setup + +Run spring boot: + +```bash +./gradlew kafka-spring-boot:bootRun +http :8585/actuator/health +``` + +### Produce + +Spring has the class `KafkaTemplate` that allows you to produce messages. + +```java +@Value("${spring.kafka.topic}") +private String topic; + +@Autowired +private KafkaTemplate kafkaTemplate; + +public void sendCustomer(Customer customer) { + log.info("Producing message: {}", customer); + kafkaTemplate.send(topic, customer.getId().toString(), customer); +} +``` + +In another terminal: + +```bash +http :8585/produce messages==10 +``` + +### Consume + +You can use the `KafkaListener` annotation. + +```java +@KafkaListener(topics = { "${spring.kafka.topic}" }) +public void consume(ConsumerRecord record) { + log.info("Customer ID: {}", record.value()); +} +``` \ No newline at end of file diff --git a/md/using-kafka/kafka-clients/kafka-clients.md b/md/using-kafka/kafka-clients/kafka-clients.md deleted file mode 100644 index 38a9155..0000000 --- a/md/using-kafka/kafka-clients/kafka-clients.md +++ /dev/null @@ -1,5 +0,0 @@ -# Kafka Clients - -Java examples for producing and consuming messages from Kafka using the -[java kafka client](https://docs.confluent.io/clients-kafka-java/current/overview.html) lib. - diff --git a/md/using-kafka/kafka-clients/spring-boot.md b/md/using-kafka/kafka-clients/spring-boot.md deleted file mode 100644 index ac0b1c8..0000000 --- a/md/using-kafka/kafka-clients/spring-boot.md +++ /dev/null @@ -1,23 +0,0 @@ -# Spring Boot - -Spring Boot + Spring Kafka producer and consumer examples. - -- [confluent spring kafka examples](https://www.confluent.io/blog/apache-kafka-spring-boot-application/) -- [spring kafka settings](https://docs.spring.io/spring-kafka/reference/html/) -- project location: [kafka-spring-boot](https://github.com/sauljabin/kafka-sandbox/tree/main/kafka-spring-boot) -- spring port: `8585` - -> ⚠️ Run these commands inside the root folder. - -Run spring boot: - -```bash -./gradlew kafka-spring-boot:bootRun -``` - -In another terminal: - -```bash -http :8585/actuator/health -http :8585/produce messages==10 -``` \ No newline at end of file