Search in sources :

Example 1 with ClientBuilderImpl

use of org.apache.pulsar.client.impl.ClientBuilderImpl in project incubator-pulsar by apache.

the class BrokerService method getReplicationClient.

public PulsarClient getReplicationClient(String cluster) {
    PulsarClient client = replicationClients.get(cluster);
    if (client != null) {
        return client;
    }
    return replicationClients.computeIfAbsent(cluster, key -> {
        try {
            String path = PulsarWebResource.path("clusters", cluster);
            ClusterData data = this.pulsar.getConfigurationCache().clustersCache().get(path).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());
            }
            if (pulsar.getConfiguration().isReplicationTlsEnabled()) {
                clientBuilder.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());
            }
            // Share all the IO threads across broker and client connections
            ClientConfigurationData conf = ((ClientBuilderImpl) clientBuilder).getClientConfigurationData();
            return new PulsarClientImpl(conf, workerGroup);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    });
}
Also used : ClientConfigurationData(org.apache.pulsar.client.impl.conf.ClientConfigurationData) ClientBuilderImpl(org.apache.pulsar.client.impl.ClientBuilderImpl) ClusterData(org.apache.pulsar.common.policies.data.ClusterData) PulsarClient(org.apache.pulsar.client.api.PulsarClient) PulsarClientImpl(org.apache.pulsar.client.impl.PulsarClientImpl) KeeperException(org.apache.zookeeper.KeeperException) ServiceUnitNotReadyException(org.apache.pulsar.broker.service.BrokerServiceException.ServiceUnitNotReadyException) NamingException(org.apache.pulsar.broker.service.BrokerServiceException.NamingException) NotAllowedException(org.apache.pulsar.broker.service.BrokerServiceException.NotAllowedException) ServerMetadataException(org.apache.pulsar.broker.service.BrokerServiceException.ServerMetadataException) IOException(java.io.IOException) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) KeeperException(org.apache.zookeeper.KeeperException) PersistenceException(org.apache.pulsar.broker.service.BrokerServiceException.PersistenceException) ClientBuilder(org.apache.pulsar.client.api.ClientBuilder)

Aggregations

IOException (java.io.IOException)1 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)1 NamingException (org.apache.pulsar.broker.service.BrokerServiceException.NamingException)1 NotAllowedException (org.apache.pulsar.broker.service.BrokerServiceException.NotAllowedException)1 PersistenceException (org.apache.pulsar.broker.service.BrokerServiceException.PersistenceException)1 ServerMetadataException (org.apache.pulsar.broker.service.BrokerServiceException.ServerMetadataException)1 ServiceUnitNotReadyException (org.apache.pulsar.broker.service.BrokerServiceException.ServiceUnitNotReadyException)1 ClientBuilder (org.apache.pulsar.client.api.ClientBuilder)1 PulsarClient (org.apache.pulsar.client.api.PulsarClient)1 PulsarClientException (org.apache.pulsar.client.api.PulsarClientException)1 ClientBuilderImpl (org.apache.pulsar.client.impl.ClientBuilderImpl)1 PulsarClientImpl (org.apache.pulsar.client.impl.PulsarClientImpl)1 ClientConfigurationData (org.apache.pulsar.client.impl.conf.ClientConfigurationData)1 ClusterData (org.apache.pulsar.common.policies.data.ClusterData)1 KeeperException (org.apache.zookeeper.KeeperException)1