use of org.apache.pulsar.client.api.ClientConfiguration in project incubator-pulsar by apache.
the class AdminApiTest method setup.
@BeforeMethod
@Override
public void setup() throws Exception {
conf.setLoadBalancerEnabled(true);
conf.setTlsEnabled(true);
conf.setTlsCertificateFilePath(TLS_SERVER_CERT_FILE_PATH);
conf.setTlsKeyFilePath(TLS_SERVER_KEY_FILE_PATH);
super.internalSetup();
bundleFactory = new NamespaceBundleFactory(pulsar, Hashing.crc32());
ClientConfiguration clientConf = new ClientConfiguration();
clientConf.setUseTls(true);
clientConf.setTlsTrustCertsFilePath(TLS_SERVER_CERT_FILE_PATH);
adminTls = spy(new PulsarAdmin(brokerUrlTls, clientConf));
// create otherbroker to test redirect on calls that need
// namespace ownership
mockPulsarSetup = new MockedPulsarService(this.conf);
mockPulsarSetup.setup();
otherPulsar = mockPulsarSetup.getPulsar();
otheradmin = mockPulsarSetup.getAdmin();
// Setup namespaces
admin.clusters().createCluster("use", new ClusterData("http://127.0.0.1" + ":" + BROKER_WEBSERVICE_PORT));
PropertyAdmin propertyAdmin = new PropertyAdmin(Lists.newArrayList("role1", "role2"), Sets.newHashSet("use"));
admin.properties().createProperty("prop-xyz", propertyAdmin);
admin.namespaces().createNamespace("prop-xyz/use/ns1");
}
use of org.apache.pulsar.client.api.ClientConfiguration 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();
}
}
use of org.apache.pulsar.client.api.ClientConfiguration in project incubator-pulsar by apache.
the class SparkStreamingPulsarReceiverExample method main.
public static void main(String[] args) throws InterruptedException {
SparkConf conf = new SparkConf().setMaster("local[*]").setAppName("pulsar-spark");
JavaStreamingContext jssc = new JavaStreamingContext(conf, Durations.seconds(5));
ClientConfiguration clientConf = new ClientConfiguration();
ConsumerConfiguration consConf = new ConsumerConfiguration();
String url = "pulsar://localhost:6650/";
String topic = "persistent://sample/standalone/ns1/topic1";
String subs = "sub1";
JavaReceiverInputDStream<byte[]> msgs = jssc.receiverStream(new SparkStreamingPulsarReceiver(clientConf, consConf, url, topic, subs));
JavaDStream<Integer> isContainingPulsar = msgs.flatMap(new FlatMapFunction<byte[], Integer>() {
@Override
public Iterator<Integer> call(byte[] msg) {
return Arrays.asList(((new String(msg)).indexOf("Pulsar") != -1) ? 1 : 0).iterator();
}
});
JavaDStream<Integer> numOfPulsar = isContainingPulsar.reduce(new Function2<Integer, Integer, Integer>() {
@Override
public Integer call(Integer i1, Integer i2) {
return i1 + i2;
}
});
numOfPulsar.print();
jssc.start();
jssc.awaitTermination();
}
use of org.apache.pulsar.client.api.ClientConfiguration in project incubator-pulsar by apache.
the class PulsarBoltTest method testFailedProducer.
@Test
public void testFailedProducer() {
PulsarBoltConfiguration pulsarBoltConf = new PulsarBoltConfiguration();
pulsarBoltConf.setServiceUrl(serviceUrl);
pulsarBoltConf.setTopic("persistent://invalid");
pulsarBoltConf.setTupleToMessageMapper(tupleToMessageMapper);
pulsarBoltConf.setMetricsTimeIntervalInSecs(60);
PulsarBolt bolt = new PulsarBolt(pulsarBoltConf, new ClientConfiguration());
MockOutputCollector mockCollector = new MockOutputCollector();
OutputCollector collector = new OutputCollector(mockCollector);
TopologyContext context = mock(TopologyContext.class);
when(context.getThisComponentId()).thenReturn("new" + methodName);
when(context.getThisTaskId()).thenReturn(0);
try {
bolt.prepare(Maps.newHashMap(), context, collector);
fail("should have failed as producer creation failed");
} catch (IllegalStateException ie) {
// Ok.
}
}
use of org.apache.pulsar.client.api.ClientConfiguration in project incubator-pulsar by apache.
the class PulsarBoltTest method setup.
@Override
protected void setup() throws Exception {
super.internalSetup();
super.producerBaseSetup();
pulsarBoltConf = new PulsarBoltConfiguration();
pulsarBoltConf.setServiceUrl(serviceUrl);
pulsarBoltConf.setTopic(topic);
pulsarBoltConf.setTupleToMessageMapper(tupleToMessageMapper);
pulsarBoltConf.setMetricsTimeIntervalInSecs(60);
bolt = new PulsarBolt(pulsarBoltConf, new ClientConfiguration());
mockCollector = new MockOutputCollector();
OutputCollector collector = new OutputCollector(mockCollector);
TopologyContext context = mock(TopologyContext.class);
when(context.getThisComponentId()).thenReturn("test-bolt-" + methodName);
when(context.getThisTaskId()).thenReturn(0);
bolt.prepare(Maps.newHashMap(), context, collector);
consumer = pulsarClient.subscribe(topic, subscriptionName);
}
Aggregations