Skip to content

Commit

Permalink
GH-2667: Use any Number for inbound x-delay property
Browse files Browse the repository at this point in the history
Fixes: #2667

The `x-delay` header may arrive as a `Short` from RabbitMQ broker.

* Fix `DefaultMessagePropertiesConverter.toMessageProperties()` to deal with a `Number`
to extract `long` value from the `x-delay` header

# Conflicts:
#	spring-rabbit/src/main/java/org/springframework/amqp/rabbit/support/DefaultMessagePropertiesConverter.java
  • Loading branch information
artembilan committed Mar 28, 2024
1 parent 3941c12 commit f8308f2
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
* @author Mark Fisher
* @author Gary Russell
* @author Soeren Unruh
* @author Artem Bilan
*
* @since 1.0
*/
public class DefaultMessagePropertiesConverter implements MessagePropertiesConverter {
Expand Down Expand Up @@ -92,8 +94,10 @@ public MessageProperties toMessageProperties(final BasicProperties source, final
String key = entry.getKey();
if (MessageProperties.X_DELAY.equals(key)) {
Object value = entry.getValue();
if (value instanceof Integer integ) {
target.setReceivedDelay(integ);
if (value instanceof Number numberValue) {
int receivedDelayLongValue = numberValue.intValue();

This comment has been minimized.

Copy link
@seanliu-oss

seanliu-oss Mar 28, 2024

Contributor

Can we make sure this is a positive number here? It was observed in the past, for whatever reason, recevedDelay was set to a negative number.

This comment has been minimized.

Copy link
@artembilan

artembilan Mar 28, 2024

Author Member

Do you mean Math.abs()?
Sure! Feel free to contribute such a fix!

target.setReceivedDelay(receivedDelayLongValue);
target.setHeader(key, receivedDelayLongValue);
}
}
else {
Expand Down Expand Up @@ -174,7 +178,7 @@ private Map<String, Object> convertHeadersIfNecessary(Map<String, Object> header
}

/**
* Converts a header value to a String if the value type is unsupported by AMQP, also handling values
* Convert a header value to a String if the value type is unsupported by AMQP, also handling values
* nested inside Lists or Maps.
* <p> {@code null} values are passed through, although Rabbit client will throw an IllegalArgumentException.
* @param valueArg the value.
Expand Down

0 comments on commit f8308f2

Please sign in to comment.