spring-cloud-stream icon indicating copy to clipboard operation
spring-cloud-stream copied to clipboard

Spring Cloud Stream don't support empty messages

Open yiliuTo opened this issue 3 years ago • 1 comments

Describe the issue Feferring the issue https://github.com/Azure/azure-sdk-for-java/issues/29564, when using com.azure.spring:spring-cloud-azure-stream-binder-servicebus, it cannot accept messages received from Service Bus claim check pattern, of which the message payload is by design empty.

Looking into the code seems it only allows Kafka to have null messages.

Expected behavior Can Spring Cloud Stream allows, in our case, Service Bus binder to have empty-payload messages? e.g., expose a configuration to allow developers to manually set whether the empty payload is allowed?

yiliuTo avatar Sep 30 '22 08:09 yiliuTo

There is no "empty payload" support in Spring Messaging and exception states clearly about that:

org.springframework.messaging.converter.MessageConversionException: Cannot convert from actual payload type 'byte[]' to expected payload type 'java.lang.String' when payload is empty
	at org.springframework.cloud.stream.config.SmartMessageMethodArgumentResolver.resolveArgument(SmartMessageMethodArgumentResolver.java:83) ~[spring-cloud-stream-3.0.13.RELEASE.jar:3.0.13.RELEASE]

BTW, Spring Cloud Stream 3.0.x is out of support for a while already: https://spring.io/projects/spring-cloud-stream#support

It might be better to revise that com.microsoft.azure.spring.integration.core.AbstractInboundChannelAdapter.receiveMessage() to return non-empty payload since the one is not supported and there is no claim that it must be.

artembilan avatar Sep 30 '22 16:09 artembilan

You can certainly use some kind of marker object or Optional as a payload, but as Artem pointed out "no empty payload" is well documented and is also not something managed by Spring Cloud Stream Also the Azure binder is not managed by this team so we can't really do much even if there was an opportunity.

olegz avatar Oct 17 '22 14:10 olegz