Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
artembilan opened this issue Nov 7, 2024 Discussed in #2889 · 0 comments
Closed

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

artembilan opened this issue Nov 7, 2024 Discussed in #2889 · 0 comments

Comments

@artembilan
Copy link
Member

Discussed in #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<Message>) {
       ...
     }

messages returns a list of byte[] which contains my payloads.

I have tried switching to List<org.springframework.messaging.Message> 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

@artembilan artembilan added this to the 3.2.0 milestone Nov 7, 2024
artembilan added a commit that referenced this issue Nov 11, 2024
Fixes: #2890
Issue link: #2890

The Kotlin function with signature `receiveBatch(messages: List<Message>)`
produced a `WildCardType` for the generic of the `List` argument.

* Fix `MessagingMessageListenerAdapter` to use `TypeUtils.isAssignable()`
to determine if the `Type` has a part as expected type

# Conflicts:
#	spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/adapter/MessagingMessageListenerAdapter.java
#	spring-rabbit/src/test/kotlin/org/springframework/amqp/rabbit/annotation/EnableRabbitKotlinTests.kt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants