From b399f2996ead0b3c23b785bebdcf3cb7ec4664ae Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Fri, 5 Mar 2021 12:59:15 -0500 Subject: [PATCH] Polish Samples --- samples/sample-01/pom.xml | 2 +- samples/sample-02/README.adoc | 2 +- samples/sample-02/pom.xml | 2 +- samples/sample-02/src/main/java/com/example/Application.java | 4 ++-- samples/sample-02/src/main/resources/application.yml | 2 ++ samples/sample-03/pom.xml | 2 +- 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/samples/sample-01/pom.xml b/samples/sample-01/pom.xml index e0ff5e14..ad011217 100644 --- a/samples/sample-01/pom.xml +++ b/samples/sample-01/pom.xml @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 2.4.2 + 2.4.3 diff --git a/samples/sample-02/README.adoc b/samples/sample-02/README.adoc index 0cd24f38..6463dce7 100644 --- a/samples/sample-02/README.adoc +++ b/samples/sample-02/README.adoc @@ -2,7 +2,7 @@ This sample demonstrates a simple producer and a multi-method consumer; the producer sends objects of types `Foo1` and `Bar1` and the consumer receives objects of type `Foo2` and `Bar2` (the objects have the same field, `foo`). -The producer uses a `JsonSerializer`; the consumer uses the `StringDeserializer` that is automatically configured by Spring Boot, together with a `StringJsonMessageConverter` which converts to the required type of the listener method argument. +The producer uses a `JsonSerializer`; the consumer uses a `ByteArrayDeserializer`, together with a `ByteArrayJsonMessageConverter` which converts to the required type of the listener method argument. We can't infer the type in this case (because the type is used to choose the method to call). We therefore configure type mapping on the producer and consumer side. See the `application.yml` for the producer side and the `converter` bean on the consumer side. diff --git a/samples/sample-02/pom.xml b/samples/sample-02/pom.xml index e1a225e8..6d5d8849 100644 --- a/samples/sample-02/pom.xml +++ b/samples/sample-02/pom.xml @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 2.4.2 + 2.4.3 diff --git a/samples/sample-02/src/main/java/com/example/Application.java b/samples/sample-02/src/main/java/com/example/Application.java index 290c442e..959388ec 100644 --- a/samples/sample-02/src/main/java/com/example/Application.java +++ b/samples/sample-02/src/main/java/com/example/Application.java @@ -29,10 +29,10 @@ import org.springframework.context.annotation.Profile; import org.springframework.kafka.core.KafkaOperations; import org.springframework.kafka.listener.DeadLetterPublishingRecoverer; import org.springframework.kafka.listener.SeekToCurrentErrorHandler; +import org.springframework.kafka.support.converter.ByteArrayJsonMessageConverter; import org.springframework.kafka.support.converter.DefaultJackson2JavaTypeMapper; import org.springframework.kafka.support.converter.Jackson2JavaTypeMapper.TypePrecedence; import org.springframework.kafka.support.converter.RecordMessageConverter; -import org.springframework.kafka.support.converter.StringJsonMessageConverter; import org.springframework.util.backoff.FixedBackOff; import com.common.Bar2; @@ -63,7 +63,7 @@ public class Application { @Bean public RecordMessageConverter converter() { - StringJsonMessageConverter converter = new StringJsonMessageConverter(); + ByteArrayJsonMessageConverter converter = new ByteArrayJsonMessageConverter(); DefaultJackson2JavaTypeMapper typeMapper = new DefaultJackson2JavaTypeMapper(); typeMapper.setTypePrecedence(TypePrecedence.TYPE_ID); typeMapper.addTrustedPackages("com.common"); diff --git a/samples/sample-02/src/main/resources/application.yml b/samples/sample-02/src/main/resources/application.yml index 0f0d52a6..cc31780f 100644 --- a/samples/sample-02/src/main/resources/application.yml +++ b/samples/sample-02/src/main/resources/application.yml @@ -4,3 +4,5 @@ spring: value-serializer: org.springframework.kafka.support.serializer.JsonSerializer properties: spring.json.type.mapping: foo:com.common.Foo1,bar:com.common.Bar1 + consumer: + value-deserializer: org.apache.kafka.common.serialization.ByteArrayDeserializer diff --git a/samples/sample-03/pom.xml b/samples/sample-03/pom.xml index 4da42ea8..705037f8 100644 --- a/samples/sample-03/pom.xml +++ b/samples/sample-03/pom.xml @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 2.4.2 + 2.4.3