本文整理汇总了Java中kafka.admin.AdminUtils.deleteTopic方法的典型用法代码示例。如果您正苦于以下问题:Java AdminUtils.deleteTopic方法的具体用法?Java AdminUtils.deleteTopic怎么用?Java AdminUtils.deleteTopic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kafka.admin.AdminUtils
的用法示例。
在下文中一共展示了AdminUtils.deleteTopic方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteTopics
import kafka.admin.AdminUtils; //导入方法依赖的package包/类
/**
* Deletes the named topics
* @param topicNames The names of the topics to delete
* @return A set of the names of the topics that were successfully deleted
*/
public String[] deleteTopics(final String...topicNames) {
if(!connected.get()) throw new IllegalStateException("The KafkaTestServer is not running");
if(topicNames==null || topicNames.length==0) return new String[0];
final Set<String> deleted = new LinkedHashSet<String>();
for(String topicName: topicNames) {
if(topicName==null || topicName.trim().isEmpty()) {
try {
AdminUtils.deleteTopic(zkUtils, topicName.trim());
deleted.add(topicName.trim());
} catch (Exception ex) {
log.warn("Failed to delete topic [" + topicName.trim() + "]", ex);
}
}
}
return deleted.toArray(new String[deleted.size()]);
}
示例2: deleteTopics
import kafka.admin.AdminUtils; //导入方法依赖的package包/类
/**
* Deletes the named topics
* @param topicNames The names of the topics to delete
* @return A set of the names of the topics that were successfully deleted
*/
public String[] deleteTopics(final String...topicNames) {
if(!running.get()) throw new IllegalStateException("The KafkaTestServer is not running");
if(topicNames==null || topicNames.length==0) return new String[0];
final Set<String> deleted = new LinkedHashSet<String>();
final ZkUtils z = getZkUtils();
for(String topicName: topicNames) {
if(topicName==null || topicName.trim().isEmpty()) {
try {
AdminUtils.deleteTopic(z, topicName.trim());
deleted.add(topicName.trim());
} catch (Exception ex) {
log.warn("Failed to delete topic [" + topicName.trim() + "]", ex);
}
}
}
return deleted.toArray(new String[deleted.size()]);
}
示例3: deleteTestTopic
import kafka.admin.AdminUtils; //导入方法依赖的package包/类
@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();
}
}
示例4: deleteTopics
import kafka.admin.AdminUtils; //导入方法依赖的package包/类
public static void deleteTopics(final KafkaEmbedded kafkaEmbedded, final String... topics) {
ZkUtils zkUtils = new ZkUtils(kafkaEmbedded.getZkClient(), null, false);
for (String topic : topics) {
if (AdminUtils.topicExists(zkUtils, topic)) {
LOGGER.info("Deleting topic {}", topic);
kafkaEmbedded.waitUntilSynced(topic, 0);
AdminUtils.deleteTopic(zkUtils, topic);
while (AdminUtils.topicExists(zkUtils, topic)) {
//wait for topic to die
}
kafkaEmbedded.waitUntilSynced(topic, 0);
}
}
}
示例5: deleteTopic
import kafka.admin.AdminUtils; //导入方法依赖的package包/类
public static void deleteTopic(String topicName) {
int sessionTimeoutMs = 10000;
int connectionTimeoutMs = 10000;
ZkUtils zkUtils =
ZkUtils.apply(testUtil.getZkUrl(), sessionTimeoutMs, connectionTimeoutMs, false);
AdminUtils.deleteTopic(zkUtils, topicName);
}
示例6: deleteTopic
import kafka.admin.AdminUtils; //导入方法依赖的package包/类
public void deleteTopic(final String topic) {
log.debug("Deleting topic { name: {} }", topic);
final ZkClient zkClient = new ZkClient(
zookeeperConnect(),
DEFAULT_ZK_SESSION_TIMEOUT_MS,
DEFAULT_ZK_CONNECTION_TIMEOUT_MS,
ZKStringSerializer$.MODULE$);
final boolean isSecure = false;
final ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(zookeeperConnect()), isSecure);
AdminUtils.deleteTopic(zkUtils, topic);
zkClient.close();
}
示例7: deleteTopic
import kafka.admin.AdminUtils; //导入方法依赖的package包/类
/**
* @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();
}
}
示例8: deleteTopic
import kafka.admin.AdminUtils; //导入方法依赖的package包/类
public void deleteTopic(final String topic) {
log.debug("Deleting topic { name: {} }", topic);
final ZkClient zkClient = new ZkClient(
zookeeperConnect(),
DEFAULT_ZK_SESSION_TIMEOUT_MS,
DEFAULT_ZK_CONNECTION_TIMEOUT_MS,
ZKStringSerializer$.MODULE$);
final boolean isSecure = false;
final ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(zookeeperConnect()), isSecure);
AdminUtils.deleteTopic(zkUtils, topic);
zkClient.close();
}
示例9: deleteTopic
import kafka.admin.AdminUtils; //导入方法依赖的package包/类
@Override
public void deleteTopic(final String topicName) {
if (AdminUtils.topicExists(zkUtils, topicName)) {
AdminUtils.deleteTopic(zkUtils, topicName);
}
throw new UnknownTopicException(topicName);
}
示例10: deleteTestTopic
import kafka.admin.AdminUtils; //导入方法依赖的package包/类
@Override
public void deleteTestTopic(String topic) {
LOG.info("Deleting topic {}", topic);
ZkClient zk = createZkClient();
AdminUtils.deleteTopic(zk, topic);
zk.close();
}
示例11: deleteTopic
import kafka.admin.AdminUtils; //导入方法依赖的package包/类
/**
* Delete topic
*
* @return if the topic was deleted or not
*/
public synchronized boolean deleteTopic(String topic) {
boolean deleted = true;
try {
AdminUtils.deleteTopic(getZooKeeperUtils(), topic);
} catch (TopicAlreadyMarkedForDeletionException topicAlreadyMarkedForDeletionException) {
deleted = false;
}
return deleted && AdminUtils.topicExists(getZooKeeperUtils(), topic);
}
示例12: tearDownClass
import kafka.admin.AdminUtils; //导入方法依赖的package包/类
@AfterClass
public static void tearDownClass() {
for (int i = 0; i < topics.length; i++) {
AdminUtils.deleteTopic(zkUtils, topics[i]);
}
kafkaServer.shutdown();
zookeeper.shutdown();
}
示例13: deleteTopic
import kafka.admin.AdminUtils; //导入方法依赖的package包/类
/**
* 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();
}
示例14: deleteKafkaTopic
import kafka.admin.AdminUtils; //导入方法依赖的package包/类
public static void deleteKafkaTopic(String zkConnString, String topicName) {
final int sessionTimeoutMillis = 10000;
final int connTimeOutMillis = 10000;
ZkClient zkClient = new ZkClient(zkConnString, sessionTimeoutMillis, connTimeOutMillis, ZKStringSerializer$.MODULE$);
try {
AdminUtils.deleteTopic(zkClient, topicName);
} catch (Exception e) {
LOG.warn("could not delete topic " + topicName + " assuming that it does not exist and moving on.", e);
}
}
示例15: stopClients
import kafka.admin.AdminUtils; //导入方法依赖的package包/类
public void stopClients() throws IOException {
for (Map.Entry<String, KafkaConsumerSuite> consumerSuiteEntry: _topicConsumerMap.entrySet())
{
consumerSuiteEntry.getValue().shutdown();
AdminUtils.deleteTopic(_kafkaServerSuite.getZkClient(), consumerSuiteEntry.getKey());
}
}