Search code examples
spring-amqp

Spring AMQP: RabbitMQ Delayed Message Exchange: `amqp_delay` not translated to `x-delay`


I have a RabbitMQ exchange of type x-delayed-message using the delayed message exchange plugin.

I know when I return a org.springframework.messaging.Message with the header AmqpHeaders.DELAY set, the delay functionality works. I would assume that the framework is at some point translating amqp_delay (value of AmqpHeaders.DELAY) to x-delay.

But when I retury a org.springframework.amqp.core.Message, the message just get's sent with the header amqp_delay instead of the x-delay header that RabbitMQ expects.

Is this an oversight on the part of Spring AMQP?

Given the AmqpHeaders class is in the spring-amqp artifact and under the org.springframework.amqp.support, shouldn't the value of AmqpHeaders.DELAY be x-delay instead of amqp_delay.

If not, shouldn't the framework atleast translate the header keys?

Or am I missing something here?


Solution

  • Such an conversion is done in the SimpleAmqpHeaderMapper:

    .acceptIfNotNull(getHeaderIfAvailable(headers, AmqpHeaders.DELAY, Integer.class),
                    amqpMessageProperties::setDelay)
    

    which is used from the MessagingMessageConverter. And this one is used in the RabbitMessagingTemplate.

    so, if you create a org.springframework.amqp.core.Message yourself, you really need to populate a x-delay header instead. The AmqpHeaders is used only in case of org.springframework.messaging.Message.