Skip to content

Commit 19ad0dc

Browse files
committedJan 30, 2024
GH-8876: Use long for AmqpHeaders.DELAY header
Fixes: #8876 * Use respective new `MessageProperties` `getDelayLong()` & `setDelayLong()`
1 parent 0ba60bc commit 19ad0dc

File tree

4 files changed

+19
-18
lines changed

4 files changed

+19
-18
lines changed
 

‎spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AbstractAmqpOutboundEndpoint.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 the original author or authors.
2+
* Copyright 2016-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -106,7 +106,7 @@ public abstract class AbstractAmqpOutboundEndpoint extends AbstractReplyProducin
106106

107107
private Expression delayExpression;
108108

109-
private ExpressionEvaluatingMessageProcessor<Integer> delayGenerator;
109+
private ExpressionEvaluatingMessageProcessor<Long> delayGenerator;
110110

111111
private boolean headersMappedLast;
112112

@@ -483,7 +483,7 @@ private void configureCorrelationDataGenerator(BeanFactory beanFactory) {
483483

484484
private void configureDelayGenerator(BeanFactory beanFactory) {
485485
if (this.delayExpression != null) {
486-
this.delayGenerator = new ExpressionEvaluatingMessageProcessor<>(this.delayExpression, Integer.class);
486+
this.delayGenerator = new ExpressionEvaluatingMessageProcessor<>(this.delayExpression, Long.class);
487487
if (beanFactory != null) {
488488
this.delayGenerator.setBeanFactory(beanFactory);
489489
}
@@ -622,7 +622,7 @@ protected String generateRoutingKey(Message<?> requestMessage) {
622622

623623
protected void addDelayProperty(Message<?> message, org.springframework.amqp.core.Message amqpMessage) {
624624
if (this.delayGenerator != null) {
625-
amqpMessage.getMessageProperties().setDelay(this.delayGenerator.processMessage(message));
625+
amqpMessage.getMessageProperties().setDelayLong(this.delayGenerator.processMessage(message));
626626
}
627627
}
628628

‎spring-integration-amqp/src/main/java/org/springframework/integration/amqp/support/DefaultAmqpHeaderMapper.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -133,7 +133,8 @@ protected Map<String, Object> extractStandardHeaders(MessageProperties amqpMessa
133133
JavaUtils.INSTANCE
134134
.acceptIfCondition(priority != null && priority > 0, IntegrationMessageHeaderAccessor.PRIORITY,
135135
priority, headers::put)
136-
.acceptIfNotNull(AmqpHeaders.RECEIVED_DELAY, amqpMessageProperties.getReceivedDelay(), headers::put)
136+
.acceptIfNotNull(AmqpHeaders.RECEIVED_DELAY, amqpMessageProperties.getReceivedDelayLong(),
137+
headers::put)
137138
.acceptIfNotNull(AmqpHeaders.RECEIVED_EXCHANGE, amqpMessageProperties.getReceivedExchange(),
138139
headers::put)
139140
.acceptIfHasText(AmqpHeaders.RECEIVED_ROUTING_KEY, amqpMessageProperties.getReceivedRoutingKey(),
@@ -196,8 +197,8 @@ protected void populateStandardHeaders(@Nullable Map<String, Object> allHeaders,
196197
amqpMessageProperties::setContentType)
197198
.acceptIfHasText(getHeaderIfAvailable(headers, AmqpHeaders.CORRELATION_ID, String.class),
198199
amqpMessageProperties::setCorrelationId)
199-
.acceptIfNotNull(getHeaderIfAvailable(headers, AmqpHeaders.DELAY, Integer.class),
200-
amqpMessageProperties::setDelay)
200+
.acceptIfNotNull(getHeaderIfAvailable(headers, AmqpHeaders.DELAY, Long.class),
201+
amqpMessageProperties::setDelayLong)
201202
.acceptIfNotNull(getHeaderIfAvailable(headers, AmqpHeaders.DELIVERY_MODE, MessageDeliveryMode.class),
202203
amqpMessageProperties::setDeliveryMode)
203204
.acceptIfNotNull(getHeaderIfAvailable(headers, AmqpHeaders.DELIVERY_TAG, Long.class),

‎spring-integration-amqp/src/test/java/org/springframework/integration/amqp/outbound/OutboundEndpointTests.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -79,19 +79,19 @@ public void testDelayExpression() {
7979
endpoint.handleMessage(new GenericMessage<>("foo"));
8080
ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
8181
verify(amqpTemplate).send(eq("foo"), eq("bar"), captor.capture(), isNull());
82-
assertThat(captor.getValue().getMessageProperties().getDelay()).isEqualTo(42);
82+
assertThat(captor.getValue().getMessageProperties().getDelayLong()).isEqualTo(42);
8383
endpoint.setExpectReply(true);
8484
endpoint.setOutputChannel(new NullChannel());
8585
endpoint.handleMessage(new GenericMessage<>("foo"));
8686
verify(amqpTemplate).sendAndReceive(eq("foo"), eq("bar"), captor.capture(), isNull());
87-
assertThat(captor.getValue().getMessageProperties().getDelay()).isEqualTo(42);
87+
assertThat(captor.getValue().getMessageProperties().getDelayLong()).isEqualTo(42);
8888

8989
endpoint.setDelay(23);
9090
endpoint.setRoutingKey("baz");
9191
endpoint.afterPropertiesSet();
9292
endpoint.handleMessage(new GenericMessage<>("foo"));
9393
verify(amqpTemplate).sendAndReceive(eq("foo"), eq("baz"), captor.capture(), isNull());
94-
assertThat(captor.getValue().getMessageProperties().getDelay()).isEqualTo(23);
94+
assertThat(captor.getValue().getMessageProperties().getDelayLong()).isEqualTo(23);
9595
}
9696

9797
@Test
@@ -114,7 +114,7 @@ public void testAsyncDelayExpression() {
114114
ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
115115
gateway.handleMessage(new GenericMessage<>("foo"));
116116
verify(amqpTemplate).sendAndReceive(eq("foo"), eq("bar"), captor.capture());
117-
assertThat(captor.getValue().getMessageProperties().getDelay()).isEqualTo(42);
117+
assertThat(captor.getValue().getMessageProperties().getDelayLong()).isEqualTo(42);
118118
}
119119

120120
@Test

‎spring-integration-amqp/src/test/java/org/springframework/integration/amqp/support/DefaultAmqpHeaderMapperTests.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -77,7 +77,7 @@ public void fromHeaders() {
7777
headerMap.put(AmqpHeaders.CONTENT_TYPE, "test.contentType");
7878
String testCorrelationId = "foo";
7979
headerMap.put(AmqpHeaders.CORRELATION_ID, testCorrelationId);
80-
headerMap.put(AmqpHeaders.DELAY, 1234);
80+
headerMap.put(AmqpHeaders.DELAY, 1234L);
8181
headerMap.put(AmqpHeaders.DELIVERY_MODE, MessageDeliveryMode.NON_PERSISTENT);
8282
headerMap.put(AmqpHeaders.DELIVERY_TAG, 1234L);
8383
headerMap.put(AmqpHeaders.EXPIRATION, "test.expiration");
@@ -111,7 +111,7 @@ public void fromHeaders() {
111111
assertThat(amqpProperties.getContentLength()).isEqualTo(99L);
112112
assertThat(amqpProperties.getContentType()).isEqualTo("test.contentType");
113113
assertThat(amqpProperties.getCorrelationId()).isEqualTo(testCorrelationId);
114-
assertThat(amqpProperties.getDelay()).isEqualTo(Integer.valueOf(1234));
114+
assertThat(amqpProperties.getDelayLong()).isEqualTo(1234L);
115115
assertThat(amqpProperties.getDeliveryMode()).isEqualTo(MessageDeliveryMode.NON_PERSISTENT);
116116
assertThat(amqpProperties.getDeliveryTag()).isEqualTo(1234L);
117117
assertThat(amqpProperties.getExpiration()).isEqualTo("test.expiration");
@@ -183,7 +183,7 @@ public void toHeaders() {
183183
amqpProperties.setMessageCount(42);
184184
amqpProperties.setMessageId("test.messageId");
185185
amqpProperties.setPriority(22);
186-
amqpProperties.setReceivedDelay(4567);
186+
amqpProperties.setReceivedDelayLong(4567L);
187187
amqpProperties.setReceivedExchange("test.receivedExchange");
188188
amqpProperties.setReceivedRoutingKey("test.receivedRoutingKey");
189189
amqpProperties.setRedelivered(true);
@@ -206,7 +206,7 @@ public void toHeaders() {
206206
assertThat(headerMap.get(AmqpHeaders.EXPIRATION)).isEqualTo("test.expiration");
207207
assertThat(headerMap.get(AmqpHeaders.MESSAGE_COUNT)).isEqualTo(42);
208208
assertThat(headerMap.get(AmqpHeaders.MESSAGE_ID)).isEqualTo("test.messageId");
209-
assertThat(headerMap.get(AmqpHeaders.RECEIVED_DELAY)).isEqualTo(4567);
209+
assertThat(headerMap.get(AmqpHeaders.RECEIVED_DELAY)).isEqualTo(4567L);
210210
assertThat(headerMap.get(AmqpHeaders.RECEIVED_EXCHANGE)).isEqualTo("test.receivedExchange");
211211
assertThat(headerMap.get(AmqpHeaders.RECEIVED_ROUTING_KEY)).isEqualTo("test.receivedRoutingKey");
212212
assertThat(headerMap.get(AmqpHeaders.REPLY_TO)).isEqualTo("test.replyTo");

0 commit comments

Comments
 (0)