Search in sources :

Example 1 with KafkaCanalConnector

use of com.alibaba.otter.canal.client.kafka.KafkaCanalConnector in project canal by alibaba.

the class KafkaClientRunningTest method testKafkaConsumer.

public void testKafkaConsumer() {
    final ExecutorService executor = Executors.newFixedThreadPool(1);
    final KafkaCanalConnector connector = new KafkaCanalConnector(servers, topic, partition, groupId, null, false);
    executor.submit(() -> {
        connector.connect();
        connector.subscribe();
        while (running) {
            List<Message> messages = connector.getList(3L, TimeUnit.SECONDS);
            if (messages != null) {
                System.out.println(messages);
            }
            connector.ack();
        }
        connector.unsubscribe();
        connector.disconnect();
    });
    sleep(60000);
    running = false;
    executor.shutdown();
    logger.info("shutdown completed");
}
Also used : Message(com.alibaba.otter.canal.protocol.Message) ExecutorService(java.util.concurrent.ExecutorService) KafkaCanalConnector(com.alibaba.otter.canal.client.kafka.KafkaCanalConnector)

Aggregations

KafkaCanalConnector (com.alibaba.otter.canal.client.kafka.KafkaCanalConnector)1 Message (com.alibaba.otter.canal.protocol.Message)1 ExecutorService (java.util.concurrent.ExecutorService)1