Skip to content

DefaultMessagePropertiesConverter#toMessageProperties should handle x-delay in Short #2667

Closed
@seanliu-oss

Description

@seanliu-oss

In what version(s) of Spring AMQP are you seeing this issue?
3.0.4
image

Describe the bug
When sending a message via delayed-message-exchange, and get the message via amqpTemplate, we get a null receivedDelay

To Reproduce
Send a message via delayed-message-exchange, with a delay of 5 seconds. The message will show up with x-delay of -5000 in the queue:
image

When using amqpTemplate to receive the message, it reaches DefaultMessagePropertiesConverter#toMessageProperties, the header value shows up as type Short:
image
image

Therefore the message will show up with receivedDelay as null.
image

While we are at it, we should also ensure receivedDelay is a positive number here, therefore a Math.abs() should help.
I did observe negative receivedDelay, but have not been able to reproduce it yet.

Expected behavior

The message should show up with receivedDelay as 5000

Sample

@SpringBootApplication
public class RabbitTestApplication implements CommandLineRunner {
@Autowired
private AmqpTemplate amqpTemplate;

public static void main(String[] args) {

    SpringApplication.run(BunyipRabbitTestApplication.class, args);
}

@Override
public void run(String... args) throws Exception {
    Message message = amqpTemplate.receive("test-delay");
}

}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions