use of org.apache.pulsar.broker.BookKeeperClientFactory in project incubator-pulsar by apache.
the class CompactorTool method main.
public static void main(String[] args) throws Exception {
Arguments arguments = new Arguments();
JCommander jcommander = new JCommander(arguments);
jcommander.setProgramName("PulsarTopicCompactor");
// parse args by JCommander
jcommander.parse(args);
if (arguments.help) {
jcommander.usage();
System.exit(-1);
}
// init broker config
ServiceConfiguration brokerConfig;
if (isBlank(arguments.brokerConfigFile)) {
jcommander.usage();
throw new IllegalArgumentException("Need to specify a configuration file for broker");
} else {
brokerConfig = PulsarConfigurationLoader.create(arguments.brokerConfigFile, ServiceConfiguration.class);
}
String pulsarServiceUrl = PulsarService.brokerUrl(brokerConfig);
ClientConfiguration clientConfig = new ClientConfiguration();
if (isNotBlank(brokerConfig.getBrokerClientAuthenticationPlugin())) {
clientConfig.setAuthentication(brokerConfig.getBrokerClientAuthenticationPlugin(), brokerConfig.getBrokerClientAuthenticationParameters());
}
clientConfig.setUseTls(brokerConfig.isTlsEnabled());
clientConfig.setTlsAllowInsecureConnection(brokerConfig.isTlsAllowInsecureConnection());
clientConfig.setTlsTrustCertsFilePath(brokerConfig.getTlsCertificateFilePath());
ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().setNameFormat("compaction-%d").setDaemon(true).build());
OrderedScheduler executor = OrderedScheduler.newSchedulerBuilder().build();
ZooKeeperClientFactory zkClientFactory = new ZookeeperBkClientFactoryImpl(executor);
ZooKeeper zk = zkClientFactory.create(brokerConfig.getZookeeperServers(), ZooKeeperClientFactory.SessionType.ReadWrite, (int) brokerConfig.getZooKeeperSessionTimeoutMillis()).get();
BookKeeperClientFactory bkClientFactory = new BookKeeperClientFactoryImpl();
BookKeeper bk = bkClientFactory.create(brokerConfig, zk);
try (PulsarClient pulsar = PulsarClient.create(pulsarServiceUrl, clientConfig)) {
Compactor compactor = new TwoPhaseCompactor(brokerConfig, pulsar, bk, scheduler);
long ledgerId = compactor.compact(arguments.topic).get();
log.info("Compaction of topic {} complete. Compacted to ledger {}", arguments.topic, ledgerId);
} finally {
bk.close();
bkClientFactory.close();
zk.close();
scheduler.shutdownNow();
executor.shutdown();
}
}
Aggregations