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");
}
Aggregations