You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Resolves#1789
Move the `SmartMessageConverter` invocations to a more logical place,
based on their expected inputs for comversion.
* Apply suggestions from code review
Copy file name to clipboardExpand all lines: spring-kafka-docs/src/main/asciidoc/kafka.adoc
+30Lines changed: 30 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4205,6 +4205,36 @@ Again, using `byte[]` or `Bytes` is more efficient because they avoid a `String`
4205
4205
For convenience, starting with version 2.3, the framework also provides a `StringOrBytesSerializer` which can serialize all three value types so it can be used with any of the message converters.
4206
4206
====
4207
4207
4208
+
Starting with version 2.7.1, message payload conversion can be delegated to a `spring-messaging` `SmartMessageConverter`; this enables conversion, for example, to be based on the `MessageHeaders.CONTENT_TYPE` header.
4209
+
4210
+
IMPORTANT: The `KafkaMessageConverter.fromMessage()` method is called for outbound conversion to a `ProducerRecord` with the message payload in the `ProducerRecord.value()` property.
4211
+
The `KafkaMessageConverter.toMessage()` method is called for inbound conversion from `ConsumerRecord` with the payload being the `ConsumerRecord.value()` property.
4212
+
The `SmartMessageConverter.toMessage()` method is called to create a new outbound `Message<?>` from the `Message` passed to`fromMessage()` (usually by `KafkaTemplate.send(Message<?> msg)`).
4213
+
Similarly, in the `KafkaMessageConverter.toMessage()` method, after the converter has created a new `Message<?>` from the `ConsumerRecord`, the `SmartMessageConverter.fromMessage()` method is called and then the final inbound message is created with the newly converted payload.
4214
+
In either case, if the `SmartMessageConverter` returns `null`, the original message is used.
4215
+
4216
+
When the default converter is used in the `KafkaTemplate` and listener container factory, you configure the `SmartMessageConverter` by calling `setMessagingConverter()` on the template and via the `contentMessageConverter` property on `@KafkaListener` methods.
Copy file name to clipboardExpand all lines: spring-kafka-docs/src/main/asciidoc/whats-new.adoc
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -85,3 +85,9 @@ See <<streams-config>> for more information.
85
85
New methods `createOrModifyTopics` and `describeTopics` have been added.
86
86
`KafkaAdmin.NewTopics` has been added to facilitate configuring multiple topics in a single bean.
87
87
See <<configuring-topics>> for more information.
88
+
89
+
[[x27-conv]]
90
+
==== `MessageConverter` Changes
91
+
92
+
It is now possible to add a `spring-messaging` `SmartMessageConverter` to the `MessagingMessageConverter`, allowing content negotiation based on the `contentType` header.
93
+
See <<messaging-message-conversion>> for more information.
Copy file name to clipboardExpand all lines: spring-kafka/src/test/java/org/springframework/kafka/support/converter/MessagingMessageConverterTests.java
0 commit comments