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"); } }
PulsarClient createClient() throws PulsarClientException { return PulsarClient.builder() .serviceUrl(serviceUrl) .build(); }
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); }
@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) //
.serviceUrl(arguments.serviceURL) //
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(); }
brokerConfig.getBrokerClientAuthenticationParameters()); clientBuilder.serviceUrl(pulsarServiceUrl) .enableTls(brokerConfig.isTlsEnabled()) .allowTlsInsecureConnection(brokerConfig.isTlsAllowInsecureConnection())
.serviceUrl(arguments.serviceURL) //
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; }
.serviceUrl(config.client.serviceUrl); if (config.client.serviceUrl.startsWith("pulsar+ssl")) { clientBuilder.enableTls(true).allowTlsInsecureConnection(config.client.tlsAllowInsecureConnection)
.serviceUrl(isNotBlank(cluster.getBrokerServiceUrlTls()) ? cluster.getBrokerServiceUrlTls() : cluster.getServiceUrlTls()) .enableTls(true) .allowTlsInsecureConnection(pulsar.getConfiguration().isTlsAllowInsecureConnection()); } else { clientBuilder.serviceUrl(isNotBlank(cluster.getBrokerServiceUrl()) ? cluster.getBrokerServiceUrl() : cluster.getServiceUrl());
.serviceUrl(isNotBlank(data.getBrokerServiceUrlTls()) ? data.getBrokerServiceUrlTls() : data.getServiceUrlTls()) .enableTls(true) .allowTlsInsecureConnection(pulsar.getConfiguration().isTlsAllowInsecureConnection()); } else { clientBuilder.serviceUrl( isNotBlank(data.getBrokerServiceUrl()) ? data.getBrokerServiceUrl() : data.getServiceUrl());
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; }