Skip to content

KafkaConsumer API

Interfaz

java
public interface KafkaConsumer<T extends SpecificRecordBase> {
    void receive(List<T> messages, List<String> keys,
                 List<Integer> partitions, List<Long> offsets);
}

Métodos

MétodoParámetrosRetornoDescripción
receive()messages, keys, partitions, offsetsvoidRecibe mensajes batch

Ejemplo de Implementación

java
@Service
public class BlankKafkaListener implements KafkaConsumer<BlankAvroModel> {
    @Autowired BlankMessageListener listener;
    @Autowired BlankMessagingDataMapper mapper;

    @KafkaListener(
        id = "${blanksystem.blank.events.journal.blank.consumer.group}",
        topics = "${blanksystem.blank.events.journal.blank.topic}"
    )
    @Override
    public void receive(List<BlankAvroModel> messages, List<String> keys,
                        List<Integer> partitions, List<Long> offsets) {
        messages.forEach(msg -> {
            try {
                listener.blankCreated(mapper.toDomain(msg));
            } catch (Exception e) {
                throw new BlankApplicationServiceException(
                    "Error processing blank: " + e.getMessage(), e);
            }
        });
    }
}

Ver también: lg5-spring-kafka documentation

Released under the MIT License.