/** * Close the AdminClient and release all associated resources. * * See {@link AdminClient#close(long, TimeUnit)} */ @Override public void close() { close(Long.MAX_VALUE, TimeUnit.MILLISECONDS); }
/** * Close the AdminClient and release all associated resources. * * The close operation has a grace period during which current operations will be allowed to * complete, specified by the given duration and time unit. * New operations will not be accepted during the grace period. Once the grace period is over, * all operations that have not yet been completed will be aborted with a TimeoutException. * * @param duration The duration to use for the wait time. * @param unit The time unit to use for the wait time. * @deprecated Since 2.2. Use {@link #close(Duration)} or {@link #close()}. */ @Deprecated public void close(long duration, TimeUnit unit) { close(Duration.ofMillis(unit.toMillis(duration))); }
public void tearDown() { logger.info("Shutting down the Kafka Consumer."); if (consumer != null) { consumer.close(); } if (adminClient != null) { adminClient.close(); adminClient = null; } try { Thread.sleep(3 * 1000); // add this sleep time to // ensure that the server is fully started before proceeding with tests. } catch (InterruptedException e) { // ignore } if (kafkaServer != null) { logger.info("Shutting down the kafka Server."); kafkaServer.stop(); } logger.info("Completed the tearDown phase."); }
public void tearDown() throws Exception { kafkaAdminClient.close(); closeProducer(); kafkaServer.shutdown(); kafkaDir.close(); zookeeper.close(); }
/** * Create an {@link AdminClient}; invoke the callback and reliably close the admin. * @param callback the callback. */ public void doWithAdmin(java.util.function.Consumer<AdminClient> callback) { Map<String, Object> adminConfigs = new HashMap<>(); adminConfigs.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, getBrokersAsString()); AdminClient admin = null; try { admin = AdminClient.create(adminConfigs); callback.accept(admin); } finally { if (admin != null) { admin.close(this.adminTimeout, TimeUnit.SECONDS); } } }
adminClient.close(this.closeTimeout, TimeUnit.SECONDS);
@Override public void close() { admin.close(); }
public void close(long duration, TimeUnit unit) { admin.close(duration, unit); }
public void close() { adminClient.close(); } }
@Test public void testAddTopics() throws Exception { AdminClient adminClient = AdminClient.create(this.admin.getConfig()); DescribeTopicsResult topics = adminClient.describeTopics(Arrays.asList("foo", "bar")); topics.all().get(); new DirectFieldAccessor(this.topic1).setPropertyValue("numPartitions", 2); new DirectFieldAccessor(this.topic2).setPropertyValue("numPartitions", 3); this.admin.initialize(); topics = adminClient.describeTopics(Arrays.asList("foo", "bar")); Map<String, TopicDescription> results = topics.all().get(); results.forEach((name, td) -> assertThat(td.partitions()).hasSize(name.equals("foo") ? 2 : 3)); adminClient.close(10, TimeUnit.SECONDS); }
@Override public void close() { adminClient.close(ADMIN_CLIENT_CLOSE_TIMEOUT_S, TimeUnit.SECONDS); log.debug("Closed."); }
@Override public synchronized void close() { if (closeCalled) return; KafkaProducer<byte[], byte[]> producer = this.producer; if (producer != null) producer.close(); AdminClient adminClient = this.adminClient; if (adminClient != null) adminClient.close(1, TimeUnit.SECONDS); closeCalled = true; }
/** * Close out the Client. */ public void close() { adminClient.close(); consumerClient.close(); } }
@Override public void close() { try { consumer.close(); } finally { adminClient.close(); } }
@Override public void close() { kafkaWorkers.close(); if (adminClient != null) adminClient.close(1, TimeUnit.SECONDS); }
@Override public void shutdown() { try { super.shutdown(); } finally { admin.close(); } }
/** * Create an {@link AdminClient}; invoke the callback and reliably close the admin. * @param callback the callback. */ public void doWithAdmin(java.util.function.Consumer<AdminClient> callback) { Map<String, Object> adminConfigs = new HashMap<>(); adminConfigs.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, getBrokersAsString()); AdminClient admin = null; try { admin = AdminClient.create(adminConfigs); callback.accept(admin); } finally { if (admin != null) { admin.close(this.adminTimeout, TimeUnit.SECONDS); } } }
@Override public void close() throws Exception { producer.close(); for (BenchmarkConsumer consumer : consumers) { consumer.close(); } admin.close(); }
void doClose() { try { if (adminClient != null) adminClient.close(1, TimeUnit.SECONDS); if (producer != null) { producer.flush(); producer.close(1, TimeUnit.SECONDS); } if (processStreams != null) processStreams.close(Duration.ofSeconds(1)); if (indexStreams != null) indexStreams.close(Duration.ofSeconds(1)); } catch (Exception | Error e) { LOG.warn("error closing client {}", e.getMessage(), e); } }
public static void createTopic(String topic, int numPartitions, short replicationFactor, Properties props) { NewTopic newTopic = new NewTopic(topic, numPartitions, replicationFactor); AdminClient adminClient = AdminClient.create(props); adminClient.createTopics(Collections.singletonList(newTopic)); adminClient.close(); } }