* to:
* contentType "text/plain" originalContentType "application/json;charset=UTF-8"{"name":"example message","description":"this is some description"}
*
+ *
+ * By means of my custom converter we end up having:
+ *
+ * contentType "application/json"{"name":"example message","description":"this is some description"}
+ *
+ * About "application/json" and character encoding:
+ * https://tools.ietf.org/html/rfc7158#section-8.1 "The default encoding is UTF-8" :)
+ *
+ *
+ *
*/
+
+
+//
+// You should set breakpoints in org.springframework.cloud.stream.binder.AbstractBinder.deserializePayload
+// org.springframework.cloud.stream.binder.AbstractBinder.serializePayloadIfNecessary
+// org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.SendingHandler.handleMessageInternal
+//
+// The code in this Spring project is a bit messy (IMHO) for example this.embedHeaders in
+// SendingHandler.handleMessageInternal: When the heck this.embedHeaders must do something? Depending on
+// the content type embedHeaders will be doing something or not. This is weird. Also deserializePayload is
+// always using UTF-8. It does not matter what character set I am receiving :/
+//
+//
+//
+//
+// Be careful when using Spring Cloud Stream because there could be surprises when trying to connect to systems
+// not using Spring (Spring is creating a mess with the headers...)
+//
+//
+
+
+
+//
+// Kafka messages WITHOUT MyCustomMessageConverter:
+// headers:
+// contentType "text/plain" <--------------- perhaps this is important.
+// originalContentType "application/json;charset=UTF-8"
+// payload:
+// {"name":"example message","description":"this is some description"}
+//
+//
+// Kafka messages WITH MyCustomMessageConverter:
+// headers:
+// contentType "application/json"
+// payload:
+// {"name":"example message","description":"this is some description"}
+//
+
+
+// YOU'D RATHER BETTER NOT USE THIS CONVERTER BECAUSE I DO NOT KNOW IF contentType "text/plain" IS IMPORTANT OR NOT :(
public class MyCustomMessageConverter extends MappingJackson2MessageConverter {
public MyCustomMessageConverter() {
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.messaging.converter.MessageConverter;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
@Configuration
public class ReceiverConfig {
}
- @Bean
- public MessageConverter customMessageConverter(ObjectMapper objectMapper) {
- MyCustomMessageConverter converter = new MyCustomMessageConverter();
- converter.setSerializedPayloadClass(String.class);
- if (objectMapper != null) {
- converter.setObjectMapper(objectMapper);
- }
-
- return converter;
- }
+// @Bean
+// public MessageConverter customMessageConverter(ObjectMapper objectMapper) {
+// MyCustomMessageConverter converter = new MyCustomMessageConverter();
+// converter.setSerializedPayloadClass(String.class);
+// if (objectMapper != null) {
+// converter.setObjectMapper(objectMapper);
+// }
+//
+// return converter;
+// }
// @Bean
@EnableBinding(Source.class)
public class Sender {
- // Aquí podrías haber usado tu custom interface: InputOutputChannels :)
+ // You could use here your custom interface. See: InputOutputChannels :)
private final Source source;
@Inject
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.messaging.converter.MessageConverter;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
@Configuration
public class SenderConfig {
return new Sender(source);
}
- @Bean
- public MessageConverter customMessageConverter(ObjectMapper objectMapper) {
- MyCustomMessageConverter converter = new MyCustomMessageConverter();
- converter.setSerializedPayloadClass(String.class);
- if (objectMapper != null) {
- converter.setObjectMapper(objectMapper);
- }
-
- return converter;
- }
+// @Bean
+// public MessageConverter customMessageConverter(ObjectMapper objectMapper) {
+// MyCustomMessageConverter converter = new MyCustomMessageConverter();
+// converter.setSerializedPayloadClass(String.class);
+// if (objectMapper != null) {
+// converter.setObjectMapper(objectMapper);
+// }
+//
+// return converter;
+// }
// @Bean
// public MessageConverter avroMessageConverter() throws IOException {
output:
binder: kafka
destination: test
- # Requires work around, see: MyCustomMessageConverter
contentType: application/json
# Consumer (input) and producer (output) are Spring Cloud Stream applications :)
headerMode: embeddedHeaders