Skip to content

Commit cebfe8a

Browse files
garyrussellartembilan
authored andcommitted
GH-2958: Also Add to Common Header in AMHEMS
Resolves #2958 The previous commit added the raw source message to a common header `IntegrationMessageHeaderAccessor.SOURCE_DATA` so that the spring-cloud-stream can construct an error message containing the data when using functions. However, we also need to add it to the common header when the `ErrorMessage` is created by Spring Integration for the normal message channel binder. This allows the DLQ processing to be agnostic as to who created the error message. (cherry picked from commit 78a0ec7)
1 parent be90fdb commit cebfe8a

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616

1717
package org.springframework.integration.amqp.support;
1818

19-
import java.util.Collections;
2019
import java.util.HashMap;
2120
import java.util.Map;
2221

2322
import org.springframework.amqp.support.AmqpHeaders;
2423
import org.springframework.core.AttributeAccessor;
24+
import org.springframework.integration.IntegrationMessageHeaderAccessor;
2525
import org.springframework.integration.support.ErrorMessageStrategy;
2626
import org.springframework.integration.support.ErrorMessageUtils;
2727
import org.springframework.lang.Nullable;
@@ -49,8 +49,11 @@ public class AmqpMessageHeaderErrorMessageStrategy implements ErrorMessageStrate
4949
public ErrorMessage buildErrorMessage(Throwable throwable, @Nullable AttributeAccessor context) {
5050
Object inputMessage = context == null ? null
5151
: context.getAttribute(ErrorMessageUtils.INPUT_MESSAGE_CONTEXT_KEY);
52-
Map<String, Object> headers = context == null ? new HashMap<String, Object>() :
53-
Collections.singletonMap(AMQP_RAW_MESSAGE, context.getAttribute(AMQP_RAW_MESSAGE));
52+
Map<String, Object> headers = new HashMap<String, Object>();
53+
if (context != null) {
54+
headers.put(AMQP_RAW_MESSAGE, context.getAttribute(AMQP_RAW_MESSAGE));
55+
headers.put(IntegrationMessageHeaderAccessor.SOURCE_DATA, context.getAttribute(AMQP_RAW_MESSAGE));
56+
}
5457
if (inputMessage instanceof Message) {
5558
return new ErrorMessage(throwable, headers, (Message<?>) inputMessage);
5659
}

0 commit comments

Comments
 (0)