Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-2662: Kafka binder DLQ root cause message #2812

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ private void handleRecordForDlq(ConsumerRecord<Object, Object> record, ConsumerD
if (message.getPayload() instanceof Throwable throwablePayload) {

throwable = throwablePayload;

String exceptionMessage = buildMessage(throwable, throwable.getCause());
HeaderMode headerMode = properties.getHeaderMode();

if (headerMode == null || HeaderMode.headers.equals(headerMode)) {
Expand All @@ -1248,7 +1248,6 @@ private void handleRecordForDlq(ConsumerRecord<Object, Object> record, ConsumerD
.getBytes(StandardCharsets.UTF_8)));
kafkaHeaders.add(new RecordHeader(X_EXCEPTION_FQCN, throwable
.getClass().getName().getBytes(StandardCharsets.UTF_8)));
String exceptionMessage = throwable.getMessage();
if (exceptionMessage != null) {
kafkaHeaders.add(new RecordHeader(X_EXCEPTION_MESSAGE,
exceptionMessage.getBytes(StandardCharsets.UTF_8)));
Expand All @@ -1271,8 +1270,7 @@ else if (HeaderMode.embeddedHeaders.equals(headerMode)) {
record.timestampType().toString());
messageValues.put(X_EXCEPTION_FQCN,
throwable.getClass().getName());
messageValues.put(X_EXCEPTION_MESSAGE,
throwable.getMessage());
messageValues.put(X_EXCEPTION_MESSAGE, exceptionMessage);
messageValues.put(X_EXCEPTION_STACKTRACE,
getStackTraceAsString(throwable));

Expand Down Expand Up @@ -1323,6 +1321,26 @@ else if (HeaderMode.embeddedHeaders.equals(headerMode)) {
}
}

@Nullable
private String buildMessage(Throwable exception, Throwable cause) {
String message = exception.getMessage();
if (!exception.equals(cause)) {
if (message != null) {
message = message + "; ";
}
String causeMsg = cause.getMessage();
if (causeMsg != null) {
if (message != null) {
message = message + causeMsg;
}
else {
message = causeMsg;
}
}
}
return message;
}

@SuppressWarnings("unchecked")
@Nullable
private KafkaAwareTransactionManager<byte[], byte[]> transactionManager(@Nullable String beanName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,7 @@ else if (!HeaderMode.none.equals(headerMode)) {
else {
assertThat(new String((byte[]) receivedMessage.getHeaders()
.get(KafkaMessageChannelBinder.X_EXCEPTION_MESSAGE))).startsWith(
"Dispatcher failed to deliver Message");
"Dispatcher failed to deliver Message; fail");
}

assertThat(receivedMessage.getHeaders()
Expand Down
Loading