I'm using Apache Camel to build integrations, and I want to persist failed messages so I can build the UI and allow user to redeliver / reprocess them when they decide it's time to do it.
I have a working example on how to send a failed messages to the dead letter queue (e.g. Kafka), but I'm struggling to persist them to the PostgreSQL.
Kafka example:
- routeConfiguration:
errorHandler:
id: errorHandler-d669
deadLetterChannel:
deadLetterUri: kafka:failed-messages?brokers=kafka:9092
redeliveryPolicy:
maximumRedeliveries: 2
redeliveryDelay: '1000'
backOffMultiplier: 2
useExponentialBackOff: true
retryAttemptedLogLevel: WARN
id: redeliveryPolicy-215f
level: ERROR
id: deadLetterChannel-6c51
id: deadletter-kafka
This will send entire Exchange message to the Kafka topic named failed-messages
and produce entry in the queue similar to this:
Exchange[Id: 7384875AE37D9B7-0000000000000004, ExchangePattern: InOnly, Properties: {CamelMessageHistory=[DefaultMessageHistory[routeId=route-5893, node=to-d19e]], CamelToEndpoint=log://deadletter-logger?level=WARN&showAll=true}, Headers: {CamelMessageTimestamp=1703585126556, Custom-Header-1=[B@1509b733, Custom-Header-2=[B@d9561f8, kafka.HEADERS=RecordHeaders(headers = [RecordHeader(key = Custom-Header-1, value = [79, 110, 101]), RecordHeader(key = Custom-Header-2, value = [84, 119, 111])], isReadOnly = false), kafka.OFFSET=11815, kafka.PARTITION=0, kafka.TIMESTAMP=1703585126556, kafka.TOPIC=failed-messages}, BodyType: String, Body: It's me, Mario, on 2023-12-26T10:05:23 - Enriched]
My problem is that when doing the same to the PostgreSQL table, I need to specify expression from which to read the failed message and I'm unable to do so:
- routeConfiguration:
errorHandler:
id: errorHandler-d679
deadLetterChannel:
deadLetterUri: >-
sql:insert into camel_deadletter (exchange_message) values (:#${SOMETHING})
redeliveryPolicy:
maximumRedeliveries: 2
redeliveryDelay: '1000'
backOffMultiplier: 2
useExponentialBackOff: true
retryAttemptedLogLevel: WARN
id: redeliveryPolicy-216f
level: ERROR
id: deadLetterChannel-6b51
id: deadletter-sql
I need to specify SOMETHING
in above's example, but I'm not sure what to put there.