Java Code Examples for kafka.admin.AdminUtils#deleteTopic()

The following examples show how to use kafka.admin.AdminUtils#deleteTopic() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KafkaTestEnvironmentImpl.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void deleteTestTopic(String topic) {
	ZkUtils zkUtils = getZkUtils();
	try {
		LOG.info("Deleting topic {}", topic);

		ZkClient zk = new ZkClient(zookeeperConnectionString, Integer.valueOf(standardProps.getProperty("zookeeper.session.timeout.ms")),
			Integer.valueOf(standardProps.getProperty("zookeeper.connection.timeout.ms")), new ZooKeeperStringSerializer());

		AdminUtils.deleteTopic(zkUtils, topic);

		zk.close();
	} finally {
		zkUtils.close();
	}
}
 
Example 2
Source File: KafkaTestEnvironmentImpl.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void deleteTestTopic(String topic) {
	ZkUtils zkUtils = getZkUtils();
	try {
		LOG.info("Deleting topic {}", topic);

		ZkClient zk = new ZkClient(zookeeperConnectionString, Integer.valueOf(standardProps.getProperty("zookeeper.session.timeout.ms")),
			Integer.valueOf(standardProps.getProperty("zookeeper.connection.timeout.ms")), new ZooKeeperStringSerializer());

		AdminUtils.deleteTopic(zkUtils, topic);

		zk.close();
	} finally {
		zkUtils.close();
	}
}
 
Example 3
Source File: KafkaTestEnvironmentImpl.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void deleteTestTopic(String topic) {
	ZkUtils zkUtils = getZkUtils();
	try {
		LOG.info("Deleting topic {}", topic);

		ZkClient zk = new ZkClient(zookeeperConnectionString, Integer.valueOf(standardProps.getProperty("zookeeper.session.timeout.ms")),
			Integer.valueOf(standardProps.getProperty("zookeeper.connection.timeout.ms")), new ZooKeeperStringSerializer());

		AdminUtils.deleteTopic(zkUtils, topic);

		zk.close();
	} finally {
		zkUtils.close();
	}
}
 
Example 4
Source File: KafkaTestEnvironmentImpl.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void deleteTestTopic(String topic) {
	ZkUtils zkUtils = getZkUtils();
	try {
		LOG.info("Deleting topic {}", topic);

		ZkClient zk = new ZkClient(zookeeperConnectionString, Integer.valueOf(standardProps.getProperty("zookeeper.session.timeout.ms")),
			Integer.valueOf(standardProps.getProperty("zookeeper.connection.timeout.ms")), new ZooKeeperStringSerializer());

		AdminUtils.deleteTopic(zkUtils, topic);

		zk.close();
	} finally {
		zkUtils.close();
	}
}
 
Example 5
Source File: KafkaTestEnvironmentImpl.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void deleteTestTopic(String topic) {
	ZkUtils zkUtils = getZkUtils();
	try {
		LOG.info("Deleting topic {}", topic);

		ZkClient zk = new ZkClient(zookeeperConnectionString, Integer.valueOf(standardProps.getProperty("zookeeper.session.timeout.ms")),
			Integer.valueOf(standardProps.getProperty("zookeeper.connection.timeout.ms")), new ZooKeeperStringSerializer());

		AdminUtils.deleteTopic(zkUtils, topic);

		zk.close();
	} finally {
		zkUtils.close();
	}
}
 
Example 6
Source File: KafkaTestEnvironmentImpl.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void deleteTestTopic(String topic) {
	ZkUtils zkUtils = getZkUtils();
	try {
		LOG.info("Deleting topic {}", topic);

		ZkClient zk = new ZkClient(zookeeperConnectionString, Integer.valueOf(standardProps.getProperty("zookeeper.session.timeout.ms")),
			Integer.valueOf(standardProps.getProperty("zookeeper.connection.timeout.ms")), new ZooKeeperStringSerializer());

		AdminUtils.deleteTopic(zkUtils, topic);

		zk.close();
	} finally {
		zkUtils.close();
	}
}
 
Example 7
Source File: TopicTest.java    From hermes with Apache License 2.0 6 votes vote down vote up
@Test
public void createTopicInTestEnv() {
	String ZOOKEEPER_CONNECT = "";
	ZkClient zkClient = new ZkClient(new ZkConnection(ZOOKEEPER_CONNECT));
	ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(ZOOKEEPER_CONNECT), false);
	zkClient.setZkSerializer(new ZKStringSerializer());
	int partition = 1;
	int replication = 1;
	String topic = String.format("kafka.test_create_topic_p%s_r%s", partition, replication);
	if (AdminUtils.topicExists(zkUtils, topic)) {
		TopicMetadata topicMetadata = AdminUtils.fetchTopicMetadataFromZk(topic, zkUtils);
		System.out.println(topicMetadata);
		AdminUtils.deleteTopic(zkUtils, topic);
	}
	AdminUtils.createTopic(zkUtils, topic, partition, replication, new Properties());
}
 
Example 8
Source File: KafkaTool.java    From Scribengin with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * This method works if cluster has "delete.topic.enable" = "true".
 * It can also be implemented by TopicCommand.deleteTopic which simply calls AdminUtils.delete 
 *
 * @param topicName
 * @throws Exception
 */
public void deleteTopic(String topicName) throws Exception {
  int sessionTimeoutMs = 10000;
  int connectionTimeoutMs = 10000;
  ZkClient zkClient = new ZkClient(zkConnects, sessionTimeoutMs, connectionTimeoutMs, ZKStringSerializer$.MODULE$);
  AdminUtils.deleteTopic(zkClient, topicName);
  zkClient.close();
}
 
Example 9
Source File: BaseKafkaZkTest.java    From brooklin with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected static void deleteTopic(ZkUtils zkUtils, String topic) {
  if (AdminUtils.topicExists(zkUtils, topic)) {
    AdminUtils.deleteTopic(zkUtils, topic);

    if (!PollUtils.poll(() -> !AdminUtils.topicExists(zkUtils, topic), 100, 25000)) {
      Assert.fail("topic was not properly deleted " + topic);
    }
  }
}
 
Example 10
Source File: KafkaResourceController.java    From pubsub with Apache License 2.0 5 votes vote down vote up
private void deleteTopic(ZkUtils zookeeperUtils) throws Exception {
  if (AdminUtils.topicExists(zookeeperUtils, topic)) {
    log.info("Deleting topic " + topic + ".");
    AdminUtils.deleteTopic(zookeeperUtils, topic);
  } else {
    log.info("Topic " + topic + " does not exist.");
  }
  while (AdminUtils.topicExists(zookeeperUtils, topic)) {
    Thread.sleep(10);
  }
}
 
Example 11
Source File: KafkaClient.java    From kafka-service-broker with Apache License 2.0 5 votes vote down vote up
void deleteTopic(String topicName) {
    ZkUtils zu = null;
    try {
        zu = util.getUtils();
        AdminUtils.deleteTopic(zu, topicName);
    } finally {
        if (zu != null) {
            zu.close();
        }
    }
}
 
Example 12
Source File: MockKafka.java    From kylin with Apache License 2.0 5 votes vote down vote up
/**
 * Delete may not work
 *
 * @param topic
 */
public void deleteTopic(String topic) {
    ZkClient zkClient = new ZkClient(zkConnection);
    ZkUtils zkUtils = new ZkUtils(zkClient, zkConnection, false);
    zkClient.setZkSerializer(new ZKStringSerializer());
    AdminUtils.deleteTopic(zkUtils, topic);
    zkClient.close();
}
 
Example 13
Source File: DataPublisherKafkaImpl.java    From kkbinlog with Apache License 2.0 5 votes vote down vote up
@Override
public boolean deleteTopic(String topicName) {

    try {
        AdminUtils.deleteTopic(zkClient, topicName);
    } catch (Exception e) {
        log.error("kafak删除topic失败", e);
        return false;
    }
    return true;
}
 
Example 14
Source File: KafkaTestBase.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
public void stopClients() throws IOException {
  for (Map.Entry<String, KafkaConsumerSuite> consumerSuiteEntry: _topicConsumerMap.entrySet())
  {
    consumerSuiteEntry.getValue().shutdown();
    AdminUtils.deleteTopic(ZkUtils.apply(_kafkaServerSuite.getZkClient(), false),
        consumerSuiteEntry.getKey());
  }
}
 
Example 15
Source File: KafkaUtils.java    From oryx with Apache License 2.0 5 votes vote down vote up
/**
 * @param zkServers Zookeeper server string: host1:port1[,host2:port2,...]
 * @param topic topic to delete, if it exists
 */
public static void deleteTopic(String zkServers, String topic) {
  ZkUtils zkUtils = ZkUtils.apply(zkServers, ZK_TIMEOUT_MSEC, ZK_TIMEOUT_MSEC, false);
  try {
    if (AdminUtils.topicExists(zkUtils, topic)) {
      log.info("Deleting topic {}", topic);
      AdminUtils.deleteTopic(zkUtils, topic);
      log.info("Deleted Zookeeper topic {}", topic);
    } else {
      log.info("No need to delete topic {} as it does not exist", topic);
    }
  } finally {
    zkUtils.close();
  }
}
 
Example 16
Source File: KafkaTestEnvironmentImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteTestTopic(String topic) {
	LOG.info("Deleting topic {}", topic);

	ZkClient zk = createZkClient();
	AdminUtils.deleteTopic(zk, topic);
	zk.close();
}
 
Example 17
Source File: KafkaTestEnvironmentImpl.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteTestTopic(String topic) {
	LOG.info("Deleting topic {}", topic);

	ZkClient zk = createZkClient();
	AdminUtils.deleteTopic(zk, topic);
	zk.close();
}
 
Example 18
Source File: KafkaTestBase.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
public void stopClients() throws IOException {
  for (Map.Entry<String, KafkaConsumerSuite> consumerSuiteEntry: _topicConsumerMap.entrySet())
  {
    consumerSuiteEntry.getValue().shutdown();
    AdminUtils.deleteTopic(_kafkaServerSuite.getZkClient(), consumerSuiteEntry.getKey());
  }
}
 
Example 19
Source File: CompositeTransactionManagerKafkaImpl.java    From microservices-transactions-tcc with Apache License 2.0 4 votes vote down vote up
@Override
public void close(String txId) {
	AdminUtils.deleteTopic(zkUtils, txId);
}
 
Example 20
Source File: TopicService.java    From kafka-monitor with Apache License 2.0 2 votes vote down vote up
/**
 * 删除topic
 *
 * @param topic topic名称
 */
public void deleteTopic(String topic) {
    AdminUtils.deleteTopic(zkUtils, topic);

}