From 58b49216213ffcd77935663aa6cb4a5af0128f10 Mon Sep 17 00:00:00 2001 From: Adrian Paschkowski Date: Sat, 7 Dec 2024 22:50:07 +0100 Subject: [PATCH] Catch errors parsing broker message headers --- .../gg/beemo/latte/broker/rabbitmq/RabbitConnection.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/latte/src/main/java/gg/beemo/latte/broker/rabbitmq/RabbitConnection.kt b/latte/src/main/java/gg/beemo/latte/broker/rabbitmq/RabbitConnection.kt index a882965..89e4bc1 100644 --- a/latte/src/main/java/gg/beemo/latte/broker/rabbitmq/RabbitConnection.kt +++ b/latte/src/main/java/gg/beemo/latte/broker/rabbitmq/RabbitConnection.kt @@ -96,9 +96,13 @@ class RabbitConnection( body: ByteArray ) { val key = envelope.routingKey ?: "" - val value = String(body) - val headers = BrokerMessageHeaders(properties.headers.mapValues { it.value.toString() }) - dispatchIncomingMessage(topic, key, value, headers) + try { + val value = String(body) + val headers = BrokerMessageHeaders(properties.headers.mapValues { it.value.toString() }) + dispatchIncomingMessage(topic, key, value, headers) + } catch (e: Exception) { + log.error("Error handling incoming broker message in topic $topic, dropping message", e) + } channel.basicAck(envelope.deliveryTag, false) }