Cecil Wei
Cecil Wei

Reputation: 23

How to use org.springframework.messaging.converter.ProtobufMessageConverter

I was trying to use Spring framework built-in ProtobufMessageConverter to convert my kafka message but I couldn't seem to find a way to have this converter being used.

The configuration of my binding is as the following:

  bindings:
    input-in-0:
      destination: test-input
      group: test-group
      content-type: application/x-protobuf;charset=UTF-8

When I use my custom message converter, I can see it registered in SimpleFunctionRegistry.messageConverter which is a list of customer converter and default ones. However, ProtobufMessageConverter doesn't seem to be included in default converters (they are registered in CompositeMessageConverterFactory.initDefaultConverters) and also filtered out by ContentTypeConfiguration.isConverterEligible if I try to instantiate it manually.

I checked the official document but it doesn't mention how to properly use the converter.I would be grateful if anyone can share your experience on how to use it.

Upvotes: 2

Views: 1282

Answers (1)

Oleg Zhurakousky
Oleg Zhurakousky

Reputation: 6126

The fact that it is registered in SimpleFunctionRegistry.messageConverter is enough. The initDefaultConverters is outdated functionality from the annotation-based support in s-c-stream and is not affecting you here (assuming you are using function-based programming model).

Anyway, in the list of converters in SimpleFunctionRegistry your converter should be the first one and should be the first one to be tried by SmartCompositeMessageConverter. What I suspect is that something is wring with the implementation of your ProtobufMessageConverter since it does not respond to application/x-protobuf;charset=UTF-8 content type when it test if this converter supports a particular message. But without seeing the implementation or having a reproducible sample it is hard to say what that may be. Perhaps you can create a bare minimum sample and push i to github somewhere so we can take a look?

Upvotes: 1

Related Questions