Spring Cloud Stream Microservice Deserialize Messages
Hello,
I have set up a Spring Cloud Stream microservice with the solace configuration. This microservice has been able to take in payloads of type string or java object, but I am now receiving SpB (protobuf) messages through solace. My goal is to deserialize these messages to JSON or POJO to be able to actually work with the data, but I have been unsuccessful at doing so.
I was wondering if Spring Cloud Stream has the functionality built in to deserialize messages of this type in an easy manner. I have been looking into @StreamListener of spring cloud stream but have not been able to get it working and do not fully understand how it works.
In addition, I have tried implementing the Eclipse Tahu project (https://github.com/eclipse/tahu/tree/master/sparkplug_b) into my microservice project but it has not been working and I feel as there must be an easier way to deserialize these messages. Please let me know if anyone knows how to go about this!
I also believe there needs to be some edits on the application.yml file of the project to declare what message type the microservice should expect to receive, but am not sure how it would look in this case. Please correct me if I'm wrong!
Thank you, Joseph
Comments
-
Hi @bensabat,
Yes this is definitely possible! I don't have a protobuf example, but you'll want to start in the Spring Cloud Stream reference guide.
- Take a read through the Content Type Negotiation section
- And note the User-defined Message Converters will probably be what you end up needing to create.
Another note, the annotation style of creating a Cloud Stream app has been deprecated so I'd suggest against using that style. Instead code your microservice using Spring Cloud Function.
Hope that helps!
2 -
Also, from a quick google I found this example: https://github.com/disc99/protocol-buffers-spring-cloud-stream/tree/master/protocol-buffers-spring-cloud-stream-starter/src/main/java/io/disc99/protocol/buffers/spring/cloud/stream
Take a look and see if that helps create the MessageConverter, but keep in mind that it's using the old annotation style for the actual coding of the app. I think you should be able to re-use the MessageConverter though.
Let us know how it goes
2