Using the new function based programming model of Spring Cloud Stream I need to have access to some of the headers of the message I consume. I figured I would consume Message<MyDto>
instead of only MyDto
, but if I do this MyDto
properties are all null.
This is in broad strokes what I want to do :
@ToString
@Getter
@Setter
public class MyDto {
private OtherDto otherDto;
}
@Bean
public Consumer<Message<MyDto>> onRawImport() {
message -> logger.info("Received {}", message.getPayload()); // <-- prints "Received MyDto(otherDto=OtherDto(...))"
}
whereas the following works perfectly in my configuration
@Bean
public Consumer<MyDto> onRawImport() {
myDto -> logger.info("Received {}", myDto); // <-- "Received MyDto(otherDto=null)"
}
Is there a simple way to consume Message directly ?
Addendum :
If I turn DEBUG on for org.springframework.cloud.function.context.catalog i see this with Consumer<MyDto>
:
BeanFactoryAwareFunctionRegistry : Applying function: onRawImport
BeanFactoryAwareFunctionRegistry : Applying type conversion on input value GenericMessage [payload=byte[288], headers=...snip...]
BeanFactoryAwareFunctionRegistry : Function type: java.util.function.Consumer<MyDto>
BeanFactoryAwareFunctionRegistry : Raw type of value: GenericMessage [payload=byte[288], ...snip...}] is class MyDto
BeanFactoryAwareFunctionRegistry : Converted from Message: MyDto(otherDto=OtherDto(...))
BeanFactoryAwareFunctionRegistry : Converted input value MyDto(otherDto=OtherDto(...))
MyOwnListener : Received MyDto(id=5, message=test)
and this with Consumer<Message<MyDto>>
BeanFactoryAwareFunctionRegistry : Applying function: onRawImport
BeanFactoryAwareFunctionRegistry : Applying type conversion on input value GenericMessage [payload=byte[288], headers=...snip...]
BeanFactoryAwareFunctionRegistry : Function type: Function type: java.util.function.Consumer<org.springframework.messaging.Message<MyDto>>
BeanFactoryAwareFunctionRegistry : Raw type of value: GenericMessage [payload=byte[288], ...snip...}] is class MyDto
BeanFactoryAwareFunctionRegistry : Converted from Message: MyDto(otherDto
=null)
BeanFactoryAwareFunctionRegistry : Converted input value MyDto(otherDto
=null)
MyOwnListener : Received MyDto(otherDto
=null)