Search in sources :

Example 26 with DeleteTopicsResult

use of org.apache.kafka.clients.admin.DeleteTopicsResult in project flink by splunk.

the class KafkaSinkITCase method deleteTestTopic.

private void deleteTestTopic(String topic) throws ExecutionException, InterruptedException, TimeoutException {
    final DeleteTopicsResult result = admin.deleteTopics(Collections.singletonList(topic));
    result.all().get(1, TimeUnit.MINUTES);
}
Also used : DeleteTopicsResult(org.apache.kafka.clients.admin.DeleteTopicsResult)

Example 27 with DeleteTopicsResult

use of org.apache.kafka.clients.admin.DeleteTopicsResult in project druid by druid-io.

the class KafkaAdminClient method deleteStream.

@Override
public void deleteStream(String streamName) throws Exception {
    DeleteTopicsResult deleteTopicsResult = adminClient.deleteTopics(ImmutableList.of(streamName));
    deleteTopicsResult.values().get(streamName).get();
}
Also used : DeleteTopicsResult(org.apache.kafka.clients.admin.DeleteTopicsResult)

Example 28 with DeleteTopicsResult

use of org.apache.kafka.clients.admin.DeleteTopicsResult in project extension-kafka by AxonFramework.

the class KafkaAdminUtils method deleteTopics.

/**
 * Method responsible for deleting the {@code topics} on the provided {@code bootstrapServer}.
 *
 * @param bootstrapServer the kafka address
 * @param topics          a list of topics to be deleted
 */
public static void deleteTopics(String bootstrapServer, String... topics) {
    try (AdminClient adminClient = AdminClient.create(minimalAdminConfig(bootstrapServer))) {
        DeleteTopicsResult topicsDeletionResult = adminClient.deleteTopics(Arrays.asList(topics));
        topicsDeletionResult.values().values().forEach(KafkaAdminUtils::waitForCompletion);
        Arrays.stream(topics).forEach(topic -> logger.info("Completed topic deletion: {}", topic));
    }
}
Also used : DeleteTopicsResult(org.apache.kafka.clients.admin.DeleteTopicsResult) AdminClient(org.apache.kafka.clients.admin.AdminClient)

Example 29 with DeleteTopicsResult

use of org.apache.kafka.clients.admin.DeleteTopicsResult in project vertx-kafka-client by vert-x3.

the class KafkaAdminClientImpl method deleteTopics.

@Override
public Future<Void> deleteTopics(List<String> topicNames) {
    ContextInternal ctx = (ContextInternal) vertx.getOrCreateContext();
    Promise<Void> promise = ctx.promise();
    DeleteTopicsResult deleteTopicsResult = this.adminClient.deleteTopics(topicNames);
    deleteTopicsResult.all().whenComplete((v, ex) -> {
        if (ex == null) {
            promise.complete();
        } else {
            promise.fail(ex);
        }
    });
    return promise.future();
}
Also used : DeleteTopicsResult(org.apache.kafka.clients.admin.DeleteTopicsResult) ContextInternal(io.vertx.core.impl.ContextInternal)

Example 30 with DeleteTopicsResult

use of org.apache.kafka.clients.admin.DeleteTopicsResult in project openmessaging-benchmark by redpanda-data.

the class RedpandaBenchmarkDriver method initialize.

@Override
public void initialize(File configurationFile, StatsLogger statsLogger) throws IOException {
    config = mapper.readValue(configurationFile, Config.class);
    Properties commonProperties = new Properties();
    commonProperties.load(new StringReader(config.commonConfig));
    producerProperties = new Properties();
    commonProperties.forEach((key, value) -> producerProperties.put(key, value));
    producerProperties.load(new StringReader(config.producerConfig));
    producerProperties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
    producerProperties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, ByteArraySerializer.class.getName());
    consumerProperties = new Properties();
    commonProperties.forEach((key, value) -> consumerProperties.put(key, value));
    consumerProperties.load(new StringReader(config.consumerConfig));
    consumerProperties.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
    consumerProperties.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, ByteArrayDeserializer.class.getName());
    topicProperties = new Properties();
    topicProperties.load(new StringReader(config.topicConfig));
    admin = AdminClient.create(commonProperties);
    if (config.reset) {
        // List existing topics
        ListTopicsResult result = admin.listTopics();
        try {
            Set<String> topics = result.names().get();
            // Delete all existing topics
            DeleteTopicsResult deletes = admin.deleteTopics(topics);
            deletes.all().get();
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
            throw new IOException(e);
        }
    }
}
Also used : ProducerConfig(org.apache.kafka.clients.producer.ProducerConfig) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) DeleteTopicsResult(org.apache.kafka.clients.admin.DeleteTopicsResult) IOException(java.io.IOException) ByteArraySerializer(org.apache.kafka.common.serialization.ByteArraySerializer) StringReader(java.io.StringReader) ListTopicsResult(org.apache.kafka.clients.admin.ListTopicsResult) ByteArrayDeserializer(org.apache.kafka.common.serialization.ByteArrayDeserializer) ExecutionException(java.util.concurrent.ExecutionException) StringSerializer(org.apache.kafka.common.serialization.StringSerializer)

Aggregations

DeleteTopicsResult (org.apache.kafka.clients.admin.DeleteTopicsResult)33 ExecutionException (java.util.concurrent.ExecutionException)12 AdminClient (org.apache.kafka.clients.admin.AdminClient)6 KafkaFuture (org.apache.kafka.common.KafkaFuture)6 IOException (java.io.IOException)4 Map (java.util.Map)4 Test (org.testng.annotations.Test)4 HashMap (java.util.HashMap)3 ListTopicsResult (org.apache.kafka.clients.admin.ListTopicsResult)3 TopicExistsException (org.apache.kafka.common.errors.TopicExistsException)3 UnknownTopicOrPartitionException (org.apache.kafka.common.errors.UnknownTopicOrPartitionException)3 ByteArrayDeserializer (org.apache.kafka.common.serialization.ByteArrayDeserializer)3 ByteArraySerializer (org.apache.kafka.common.serialization.ByteArraySerializer)3 StringDeserializer (org.apache.kafka.common.serialization.StringDeserializer)3 StringSerializer (org.apache.kafka.common.serialization.StringSerializer)3 KafkaResponseGetFailedException (io.confluent.ksql.exception.KafkaResponseGetFailedException)2 StringReader (java.io.StringReader)2 ParseException (java.text.ParseException)2 OptionException (joptsimple.OptionException)2 Cleanup (lombok.Cleanup)2