🎄 Happy Holidays! 🥳
Most of Solace is closed December 24–January 1 so our employees can spend time with their families. We will re-open Thursday, January 2, 2024. Please expect slower response times during this period and open a support ticket for anything needing immediate assistance.
Happy Holidays!
Please note: most of Solace is closed December 25–January 2, and will re-open Tuesday, January 3, 2023.
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