GH-2667: Use any Number for inbound x-delay property

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
This commit is contained in:
Artem Bilan
2024-03-28 11:32:48 -04:00
parent 3941c1270d
commit f8308f222e

View File

@@ -40,6 +40,8 @@ import com.rabbitmq.client.LongString;
* @author Mark Fisher
* @author Gary Russell
* @author Soeren Unruh
* @author Artem Bilan
*
* @since 1.0
*/
public class DefaultMessagePropertiesConverter implements MessagePropertiesConverter {
@@ -92,8 +94,10 @@ public class DefaultMessagePropertiesConverter implements MessagePropertiesConve
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();
target.setReceivedDelay(receivedDelayLongValue);
target.setHeader(key, receivedDelayLongValue);
}
}
else {
@@ -174,7 +178,7 @@ public class DefaultMessagePropertiesConverter implements MessagePropertiesConve
}
/**
* 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.