Skip to content

Commit dc2e0dd

Browse files
committed
Reason added to headers
1 parent 225fb97 commit dc2e0dd

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

ebms-async/src/main/kotlin/no/nav/emottak/ebms/async/App.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ fun Route.simulateError(): Route = get("/api/forceretry/{$KAFKA_OFFSET}") {
244244
(call.parameters[KAFKA_OFFSET])?.toLong() ?: 0
245245
)
246246
failedMessageQueue.sendToRetry(
247-
record = record ?: throw Exception("No Record found. Offset: ${call.parameters[KAFKA_OFFSET]}")
247+
record = record ?: throw Exception("No Record found. Offset: ${call.parameters[KAFKA_OFFSET]}"),
248+
reason = "Simulated Error"
248249
)
249250
}
250251
}

ebms-async/src/main/kotlin/no/nav/emottak/ebms/async/kafka/consumer/FailedMessageKafkaHandler.kt

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import kotlin.time.Duration.Companion.seconds
3333
val failedMessageQueue: FailedMessageKafkaHandler = FailedMessageKafkaHandler()
3434
const val RETRY_COUNT_HEADER = "retryCount"
3535
const val RETRY_AFTER = "retryableAfter"
36+
const val RETRY_REASON = "retryReason"
3637

3738
val logger = LoggerFactory.getLogger(FailedMessageKafkaHandler::class.java)
3839

@@ -65,8 +66,12 @@ class FailedMessageKafkaHandler(
6566
suspend fun sendToRetry(
6667
record: ReceiverRecord<String, ByteArray>,
6768
key: String = record.key(),
68-
value: ByteArray = record.value()
69+
value: ByteArray = record.value(),
70+
reason: String? = null
6971
) {
72+
if (reason != null) {
73+
record.addHeader(RETRY_REASON, reason)
74+
}
7075
record.addHeader(RETRY_AFTER, getNextRetryTime(record))
7176
try {
7277
val metadata = publisher.publishScope {

ebms-async/src/main/kotlin/no/nav/emottak/ebms/async/processing/PayloadMessageProcessor.kt

+6-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,12 @@ class PayloadMessageProcessor(
9797
returnMessageError(ebmsPayloadMessage, e)
9898
} catch (ex: Exception) {
9999
log.error(ebmsPayloadMessage.marker(), ex.message ?: "Unknown error", ex)
100-
failedMessageQueue.sendToRetry(record, ebmsPayloadMessage.requestId, ebmsPayloadMessage.toEbmsDokument().dokument.asByteArray())
100+
failedMessageQueue.sendToRetry(
101+
record,
102+
ebmsPayloadMessage.requestId,
103+
ebmsPayloadMessage.toEbmsDokument().dokument.asByteArray(),
104+
ex.message ?: "Unknown error"
105+
)
101106
throw ex
102107
}
103108
}

0 commit comments

Comments
 (0)