@@ -12,14 +12,14 @@ import {
1212 type ConsumerOptions ,
1313 type Message ,
1414 type MessagesStream ,
15- jsonDeserializer ,
1615 stringDeserializer ,
1716} from '@platformatic/kafka'
1817import { AbstractKafkaService , type BaseKafkaOptions } from './AbstractKafkaService.ts'
1918import { KafkaHandlerContainer } from './handler-container/KafkaHandlerContainer.ts'
2019import type { KafkaHandlerRouting } from './handler-container/KafkaHandlerRoutingBuilder.ts'
2120import type { KafkaHandler , RequestContext } from './handler-container/index.ts'
2221import type { KafkaConfig , KafkaDependencies , TopicConfig } from './types.ts'
22+ import { safeJsonDeserializer } from './utils/safeJsonDeserializer.js'
2323
2424export type KafkaConsumerDependencies = KafkaDependencies &
2525 Pick < QueueConsumerDependencies , 'transactionObservabilityManager' >
@@ -66,7 +66,7 @@ export abstract class AbstractKafkaConsumer<
6666 autocommit : false , // Handling commits manually
6767 deserializers : {
6868 key : stringDeserializer ,
69- value : jsonDeserializer ,
69+ value : safeJsonDeserializer ,
7070 headerKey : stringDeserializer ,
7171 headerValue : stringDeserializer ,
7272 } ,
@@ -102,6 +102,9 @@ export abstract class AbstractKafkaConsumer<
102102 }
103103
104104 private async consume ( message : Message < string , object , string , string > ) : Promise < void > {
105+ // message.value can be undefined if the message is not JSON-serializable
106+ if ( ! message . value ) return message . commit ( )
107+
105108 const handler = this . handlerContainer . resolveHandler ( message . topic , message . value )
106109 // if there is no handler for the message, we ignore it (simulating subscription)
107110 if ( ! handler ) return message . commit ( )
0 commit comments