Spring Cloud Stream Data Type in Function
Function<Message<?>, Message<?>>
The function takes the input paylaod as bytes even when datatype is mentioned. The auto conversion from json to pojo is not happening.
Any suggestion?
For example, Message<ClassName> when i directly use it, i am getting Class class exception
ClassName a = message.getPayload().
Works as only this : String messageBytes = new String((byte[]) payload, StandardCharsets.UTF_8);
Answers
-
Hi @kirthi ,
If you haven't already I would suggest reading through the Content Negotiation section of the Spring Cloud Stream reference guide. It does a good job at explaining all of the options, including Provided Message Converters and how you can create custom ones. If you are getting a class cast exception then there is an issue where it can't parse the inbound payload into the expected object. Does the exception give you any details that help? otherwise you might have to debug the code to see what it's failing on.
Note that by default if your signature says
Function<Message<Foo>,Message<Bar>>
then on the input binding it will try to convert the object into aFoo
POJO and on the outbound side it will expect aBar
object to be returned.Hope that helps.
1 -
Hi All,
Please suggest for the below scenario;
Function<Message<List<?>>, Collection<//User Defined Object//>> receiveMessage()
Will we be able to publish the payload as object instead of wrapping it in org.springframework.messaging.Message with messageBuilder?
Will the next microservice can it receive as the same Object?
Function<//User Defined Object//, //User Defined Object//>> messageReceiver();
Exception Occured while testing :
nested exception is com.solace.spring.cloud.stream.binder.util.SolaceMessageConversionException: Invalid payload received. Expected byte[], String, SDTStream, SDTMap, Serializable.
Should the message always be wrapped as message?..
0 -
Thanks @marc
Producing application:
spring.cloud.stream.bindings.receiveMessage-out-0.content-type=application/json
spring.cloud.stream.bindings.receiveMessage-out-0.producer.content-type=application/json
Receving application;
spring.cloud.stream.bindings.messageReceiver-in-0.content-type=application/json
spring.cloud.stream.bindings.messageReceiver-in-0.consumer.content-type=application/json
Is this is the intended property?
0