protected void testPulsarFunctionality(String pulsarBrokerUrl) throws Exception { try ( PulsarClient client = PulsarClient.builder() .serviceUrl(pulsarBrokerUrl) .build(); Consumer consumer = client.newConsumer() .topic(TEST_TOPIC) .subscriptionName("test-subs") .subscribe(); Producer<byte[]> producer = client.newProducer() .topic(TEST_TOPIC) .create() ) { producer.send("test containers".getBytes()); CompletableFuture<Message> future = consumer.receiveAsync(); Message message = future.get(5, TimeUnit.SECONDS); assertThat(new String(message.getData())) .isEqualTo("test containers"); } }
private PulsarClient createClientInstance(ClusterData clusterData) throws IOException { ClientBuilder clientBuilder = PulsarClient.builder() // .statsInterval(0, TimeUnit.SECONDS) // .enableTls(config.isTlsEnabled()) // .allowTlsInsecureConnection(config.isTlsAllowInsecureConnection()) // .tlsTrustCertsFilePath(config.getBrokerClientTrustCertsFilePath()) // .ioThreads(config.getWebSocketNumIoThreads()) // .connectionsPerBroker(config.getWebSocketConnectionsPerBroker()); if (isNotBlank(config.getBrokerClientAuthenticationPlugin()) && isNotBlank(config.getBrokerClientAuthenticationParameters())) { clientBuilder.authentication(config.getBrokerClientAuthenticationPlugin(), config.getBrokerClientAuthenticationParameters()); } if (config.isTlsEnabled()) { if (isNotBlank(clusterData.getBrokerServiceUrlTls())) { clientBuilder.serviceUrl(clusterData.getBrokerServiceUrlTls()); } else if (isNotBlank(clusterData.getServiceUrlTls())) { clientBuilder.serviceUrl(clusterData.getServiceUrlTls()); } } else if (isNotBlank(clusterData.getBrokerServiceUrl())) { clientBuilder.serviceUrl(clusterData.getBrokerServiceUrl()); } else { clientBuilder.serviceUrl(clusterData.getServiceUrl()); } return clientBuilder.build(); }
private static PulsarClient createPulsarClient(String pulsarServiceUrl, AuthenticationConfig authConfig) throws PulsarClientException { ClientBuilder clientBuilder = null; if (isNotBlank(pulsarServiceUrl)) { clientBuilder = PulsarClient.builder().serviceUrl(pulsarServiceUrl); if (authConfig != null) { if (isNotBlank(authConfig.getClientAuthenticationPlugin()) && isNotBlank(authConfig.getClientAuthenticationParameters())) { clientBuilder.authentication(authConfig.getClientAuthenticationPlugin(), authConfig.getClientAuthenticationParameters()); } clientBuilder.enableTls(authConfig.isUseTls()); clientBuilder.allowTlsInsecureConnection(authConfig.isTlsAllowInsecureConnection()); clientBuilder.enableTlsHostnameVerification(authConfig.isTlsHostnameVerificationEnable()); clientBuilder.tlsTrustCertsFilePath(authConfig.getTlsTrustCertsFilePath()); } return clientBuilder.build(); } return null; }
try { ClientBuilder clientBuilder = PulsarClient.builder() .enableTcpNoDelay(false) .statsInterval(0, TimeUnit.SECONDS); clientBuilder.authentication(pulsar.getConfiguration().getBrokerClientAuthenticationPlugin(), pulsar.getConfiguration().getBrokerClientAuthenticationParameters()); .serviceUrl(isNotBlank(cluster.getBrokerServiceUrlTls()) ? cluster.getBrokerServiceUrlTls() : cluster.getServiceUrlTls()) .enableTls(true) .tlsTrustCertsFilePath(pulsar.getConfiguration().getBrokerClientTrustCertsFilePath()) .allowTlsInsecureConnection(pulsar.getConfiguration().isTlsAllowInsecureConnection()); } else { clientBuilder.serviceUrl(isNotBlank(cluster.getBrokerServiceUrl()) ? cluster.getBrokerServiceUrl() : cluster.getServiceUrl());
private void updateConfig() throws UnsupportedAuthenticationException, MalformedURLException { ClientBuilder clientBuilder = PulsarClient.builder(); if (isNotBlank(this.authPluginClassName)) { clientBuilder.authentication(authPluginClassName, authParams); } clientBuilder.allowTlsInsecureConnection(this.tlsAllowInsecureConnection); clientBuilder.tlsTrustCertsFilePath(this.tlsTrustCertsFilePath); clientBuilder.serviceUrl(serviceURL); this.produceCommand.updateConfig(clientBuilder); this.consumeCommand.updateConfig(clientBuilder); }
PulsarClient client = clientBuilder.build(); Producer<byte[]> producer = client.newProducer().topic(topic).create();
.serviceUrl(arguments.serviceURL) // .connectionsPerBroker(arguments.maxConnections) // .statsInterval(arguments.statsIntervalSeconds, TimeUnit.SECONDS) // .ioThreads(Runtime.getRuntime().availableProcessors()) // .enableTls(arguments.useTls) // .tlsTrustCertsFilePath(arguments.tlsTrustCertsFilePath); clientBuilder.authentication(arguments.authPluginClassName, arguments.authParams); PulsarClient pulsarClient = clientBuilder.build();
public synchronized PulsarClient getClient() throws PulsarServerException { if (this.client == null) { try { ClientBuilder builder = PulsarClient.builder() .serviceUrl(this.getConfiguration().isTlsEnabled() ? this.brokerServiceUrlTls : this.brokerServiceUrl) .enableTls(this.getConfiguration().isTlsEnabled()) .allowTlsInsecureConnection(this.getConfiguration().isTlsAllowInsecureConnection()) .tlsTrustCertsFilePath(this.getConfiguration().getTlsCertificateFilePath()); if (isNotBlank(this.getConfiguration().getBrokerClientAuthenticationPlugin())) { builder.authentication(this.getConfiguration().getBrokerClientAuthenticationPlugin(), this.getConfiguration().getBrokerClientAuthenticationParameters()); } this.client = builder.build(); } catch (Exception e) { throw new PulsarServerException(e); } } return this.client; }
.orElseThrow(() -> new KeeperException.NoNodeException(path)); ClientBuilder clientBuilder = PulsarClient.builder() .enableTcpNoDelay(false) .connectionsPerBroker(pulsar.getConfiguration().getReplicationConnectionsPerBroker()) .statsInterval(0, TimeUnit.SECONDS); if (pulsar.getConfiguration().isAuthenticationEnabled()) { clientBuilder.authentication(pulsar.getConfiguration().getBrokerClientAuthenticationPlugin(), pulsar.getConfiguration().getBrokerClientAuthenticationParameters()); .serviceUrl(isNotBlank(data.getBrokerServiceUrlTls()) ? data.getBrokerServiceUrlTls() : data.getServiceUrlTls()) .enableTls(true) .tlsTrustCertsFilePath(pulsar.getConfiguration().getBrokerClientTrustCertsFilePath()) .allowTlsInsecureConnection(pulsar.getConfiguration().isTlsAllowInsecureConnection()); } else { clientBuilder.serviceUrl( isNotBlank(data.getBrokerServiceUrl()) ? data.getBrokerServiceUrl() : data.getServiceUrl());
PulsarClient client = clientBuilder.build(); Consumer<byte[]> consumer = client.newConsumer().topic(topic).subscriptionName(this.subscriptionName).subscriptionType(subscriptionType).subscribe();
log.info("Pulsar driver configuration: {}", writer.writeValueAsString(config)); ClientBuilder clientBuilder = PulsarClient.builder().ioThreads(config.client.ioThreads) .connectionsPerBroker(config.client.connectionsPerBroker).statsInterval(0, TimeUnit.SECONDS) .serviceUrl(config.client.serviceUrl); if (config.client.serviceUrl.startsWith("pulsar+ssl")) { clientBuilder.enableTls(true).allowTlsInsecureConnection(config.client.tlsAllowInsecureConnection) .enableTlsHostnameVerification(config.client.tlsEnableHostnameVerification) .tlsTrustCertsFilePath(config.client.tlsTrustCertsFilePath); clientBuilder.authentication(config.client.authentication.plugin, config.client.authentication.data); pulsarAdminBuilder.authentication(config.client.authentication.plugin, config.client.authentication.data); client = clientBuilder.build();
clientBuilder.authentication(brokerConfig.getBrokerClientAuthenticationPlugin(), brokerConfig.getBrokerClientAuthenticationParameters()); clientBuilder.serviceUrl(pulsarServiceUrl) .enableTls(brokerConfig.isTlsEnabled()) .allowTlsInsecureConnection(brokerConfig.isTlsAllowInsecureConnection()) .tlsTrustCertsFilePath(brokerConfig.getTlsCertificateFilePath()); BookKeeperClientFactory bkClientFactory = new BookKeeperClientFactoryImpl(); BookKeeper bk = bkClientFactory.create(brokerConfig, zk); try (PulsarClient pulsar = clientBuilder.build()) { Compactor compactor = new TwoPhaseCompactor(brokerConfig, pulsar, bk, scheduler); long ledgerId = compactor.compact(arguments.topic).get();
PulsarClient createClient() throws PulsarClientException { return PulsarClient.builder() .serviceUrl(serviceUrl) .build(); }
.serviceUrl(arguments.serviceURL) // .connectionsPerBroker(arguments.maxConnections) // .statsInterval(arguments.statsIntervalSeconds, TimeUnit.SECONDS) // .ioThreads(Runtime.getRuntime().availableProcessors()) // .enableTls(arguments.useTls) // .tlsTrustCertsFilePath(arguments.tlsTrustCertsFilePath); if (isNotBlank(arguments.authPluginClassName)) { clientBuilder.authentication(arguments.authPluginClassName, arguments.authParams); PulsarClient pulsarClient = clientBuilder.build();
@Override public void start() { try { client = PulsarClient.builder() .serviceUrl(serviceUrl) .build(); log.info("Successfully created pulsar client to {}", serviceUrl); producer = client.newProducer(Schema.BYTES) .topic(topic) .create(); log.info("Successfully created producer to produce updates to topic {}", topic); reader = client.newReader(Schema.BYTES) .topic(topic) .startMessageId(MessageId.earliest) .create(); log.info("Successfully created reader to replay updates from topic {}", topic); CompletableFuture<Void> endFuture = new CompletableFuture<>(); readToEnd(endFuture); endFuture.join(); } catch (PulsarClientException e) { log.error("Failed to create pulsar client to cluster at {}", serviceUrl, e); throw new RuntimeException("Failed to create pulsar client to cluster at " + serviceUrl, e); } }
.serviceUrl(arguments.serviceURL) // .connectionsPerBroker(arguments.maxConnections) // .ioThreads(Runtime.getRuntime().availableProcessors()) // .statsInterval(arguments.statsIntervalSeconds, TimeUnit.SECONDS) // .enableTls(arguments.useTls) // .tlsTrustCertsFilePath(arguments.tlsTrustCertsFilePath); clientBuilder.authentication(arguments.authPluginClassName, arguments.authParams); PulsarClient client = clientBuilder.build(); ProducerBuilder<byte[]> producerBuilder = client.newProducer() // .sendTimeout(0, TimeUnit.SECONDS) //