spring-projects / spring-amqp

Spring AMQP - support for Spring programming model with AMQP, especially but not limited to RabbitMQ
https://spring.io/projects/spring-amqp
Apache License 2.0
811 stars 627 forks source link

byte[] received when using @RabbitListener with Batching #2890

Closed artembilan closed 2 weeks ago

artembilan commented 2 weeks ago

Discussed in https://github.com/spring-projects/spring-amqp/discussions/2889

Originally posted by **arths31** November 6, 2024 Hello, I'm having an issue when using @RabbitListener with batching enabled. Batching works fine but I want to receive a list of **org.springframework.amqp.core.Message** and I am receiving a list of **byte[]** instead. Here is the bean I use to configure the containerFactory ``` @Bean fun myFactory(configurer: SimpleRabbitListenerContainerFactoryConfigurer): SimpleRabbitListenerContainerFactory { val factory = SimpleRabbitListenerContainerFactory() factory.setConnectionFactory(connectionFactory) factory.setBatchListener(true) factory.setBatchSize(10) factory.setConsumerBatchEnabled(true) factory.setDeBatchingEnabled(false) factory.setReceiveTimeout(5000) return factory } ``` and here is where I expect to receive my messages ``` @RabbitListener(bindings = [ QueueBinding( value = org.springframework.amqp.rabbit.annotation.Queue(name = "test", durable = "true"), key = ["xxx.#"], exchange = Exchange(name = Constants.EVENT_EXCHANGE_NAME, type = ExchangeTypes.TOPIC) ) ], containerFactory = "myFactory") fun listen(messages: List) { ... } ``` **messages** returns a list of byte[] which contains my payloads. I have tried switching to **List>** and even a list of String just like in the following exemple but to no avail : https://docs.spring.io/spring-amqp/reference/amqp/receiving-messages/batch.html Thank you in advance for your help