Lambda function returning null parameters when receiving Kafka event

21 Views Asked by At

I am developing a lambda function that receives events from a Kafka connector and Avro schema but when invoked, it is returning null values ​​as per the log below:

Event received: KafkaEvent(records=null, eventSource=null, eventSourceArn=null, bootstrapServers=null)

Handler Class:

public class Handler implements RequestHandler<KafkaEvent, String> {

    private final ManagerUseCase useCase;

    public Handler() {
        this.useCase = new ManagerUseCase ();
    }

    public Handler(ManagerUseCase useCase) {
        this.useCase = useCase;
    }

    @Override
    public String handleRequest(KafkaEvent event, Context context) {
        out.println("Event received: " + event);

        if (event == null) {
            out.println("Null event!");
            return "Processing not completed!";
        }

        if (event.getRecords() == null) {
            out.println("Null record list!");
            return "Processing not completed!";
        }

        if (event.getRecords().isEmpty() || event.getRecords().values().stream().anyMatch(List::isEmpty)) {
            out.println("Event without registrations!");
            return "Processing not completed!";
        }

        event.getRecords().values().stream()
                .flatMap(List::stream)
                .forEach(kafkaEventRecord -> useCase.processarEventoHandler(kafkaEventRecord.getValue()));

        return "Processing completed!";
    }
}

Observation: I'm using Avro schema which is processed in the UseCase class and it is deserialized using Decoder (I'll leave the method below for you to see) and I'm using Java 17.

private ComandEventClients deserializeAvro(String avro) throws IOException {
        DatumReader<ComandEventClients> reader = new SpecificDatumReader<>(ComandEventClients.class);
        Decoder decoder = DecoderFactory.get().jsonDecoder(ComandEventClients.getClassSchema(), avro);
        log.info("Deserializing message: {}", avro);
        return reader.read(null, decoder);
    }

Avro stub: ComandEventClients

Does anyone know what can it be? Thanks in advance!

0

There are 0 best solutions below