Java Code Examples for org.apache.pulsar.broker.ServiceConfiguration#setLoadBalancerEnabled()

The following examples show how to use org.apache.pulsar.broker.ServiceConfiguration#setLoadBalancerEnabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BrokerAdminClientTlsAuthTest.java    From pulsar with Apache License 2.0 6 votes vote down vote up
private void buildConf(ServiceConfiguration conf) {
    conf.setLoadBalancerEnabled(true);
    conf.setTlsCertificateFilePath(getTLSFile("broker.cert"));
    conf.setTlsKeyFilePath(getTLSFile("broker.key-pk8"));
    conf.setTlsTrustCertsFilePath(getTLSFile("ca.cert"));
    conf.setAuthenticationEnabled(true);
    conf.setSuperUserRoles(ImmutableSet.of("superproxy", "broker.pulsar.apache.org"));
    conf.setAuthenticationProviders(
            ImmutableSet.of("org.apache.pulsar.broker.authentication.AuthenticationProviderTls"));
    conf.setAuthorizationEnabled(true);
    conf.setBrokerClientTlsEnabled(true);
    String str = String.format("tlsCertFile:%s,tlsKeyFile:%s", getTLSFile("broker.cert"), getTLSFile("broker.key-pk8"));
    conf.setBrokerClientAuthenticationParameters(str);
    conf.setBrokerClientAuthenticationPlugin("org.apache.pulsar.client.impl.auth.AuthenticationTls");
    conf.setBrokerClientTrustCertsFilePath(getTLSFile("ca.cert"));
    conf.setTlsAllowInsecureConnection(true);
}
 
Example 2
Source File: TopicOwnerTest.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@BeforeMethod
void setup() throws Exception {
    log.info("---- Initializing TopicOwnerTest -----");
    // Start local bookkeeper ensemble
    bkEnsemble = new LocalBookkeeperEnsemble(3, 0, () -> 0);
    bkEnsemble.start();

    // start brokers
    for (int i = 0; i < BROKER_COUNT; i++) {
        ServiceConfiguration config = new ServiceConfiguration();
        config.setBrokerServicePort(Optional.of(0));
        config.setClusterName("my-cluster");
        config.setAdvertisedAddress("localhost");
        config.setWebServicePort(Optional.of(0));
        config.setZookeeperServers("127.0.0.1" + ":" + bkEnsemble.getZookeeperPort());
        config.setDefaultNumberOfNamespaceBundles(1);
        config.setLoadBalancerEnabled(false);
        configurations[i] = config;

        pulsarServices[i] = new PulsarService(config);
        pulsarServices[i].start();

        pulsarAdmins[i] = PulsarAdmin.builder()
                .serviceHttpUrl(pulsarServices[i].getWebServiceAddress())
                .build();
    }
    Thread.sleep(1000);
}
 
Example 3
Source File: TransactionMetaStoreTestBase.java    From pulsar with Apache License 2.0 4 votes vote down vote up
@BeforeClass
void setup() throws Exception {
    log.info("---- Initializing SLAMonitoringTest -----");
    // Start local bookkeeper ensemble
    bkEnsemble = new LocalBookkeeperEnsemble(3, 0, () -> 0);
    bkEnsemble.start();

    String[] args = new String[]{
        "--cluster", "my-cluster",
        "--configuration-store", "localhost:" + bkEnsemble.getZookeeperPort(),
        "--initial-num-transaction-coordinators", "16"};

    PulsarTransactionCoordinatorMetadataSetup.main(args);

    // start brokers
    for (int i = 0; i < BROKER_COUNT; i++) {
        ServiceConfiguration config = new ServiceConfiguration();
        config.setBrokerServicePort(Optional.of(0));
        config.setClusterName("my-cluster");
        config.setAdvertisedAddress("localhost");
        config.setWebServicePort(Optional.of(0));
        config.setZookeeperServers("127.0.0.1" + ":" + bkEnsemble.getZookeeperPort());
        config.setDefaultNumberOfNamespaceBundles(1);
        config.setLoadBalancerEnabled(false);
        configurations[i] = config;

        pulsarServices[i] = new PulsarService(config);
        pulsarServices[i].start();

        pulsarAdmins[i] = PulsarAdmin.builder()
                .serviceHttpUrl(pulsarServices[i].getWebServiceAddress())
                .build();
    }

    Thread.sleep(100);

    PulsarClient client = PulsarClient.builder().
        serviceUrl(pulsarServices[0].getBrokerServiceUrl())
        .build();
    transactionCoordinatorClient = new TransactionCoordinatorClientImpl(client);
    transactionCoordinatorClient.start();

    Thread.sleep(3000);
}
 
Example 4
Source File: AntiAffinityNamespaceGroupTest.java    From pulsar with Apache License 2.0 4 votes vote down vote up
@BeforeMethod
void setup() throws Exception {
    executor = new ThreadPoolExecutor(5, 20, 30, TimeUnit.SECONDS,
            new LinkedBlockingQueue<Runnable>());
    // Start local bookkeeper ensemble
    bkEnsemble = new LocalBookkeeperEnsemble(3, 0, () -> 0);
    bkEnsemble.start();

    // Start broker 1
    ServiceConfiguration config1 = new ServiceConfiguration();
    config1.setLoadManagerClassName(ModularLoadManagerImpl.class.getName());
    config1.setClusterName("use");
    config1.setWebServicePort(Optional.of(0));
    config1.setZookeeperServers("127.0.0.1" + ":" + bkEnsemble.getZookeeperPort());
    config1.setBrokerServicePort(Optional.of(0));
    config1.setFailureDomainsEnabled(true);
    config1.setLoadBalancerEnabled(true);
    config1.setAdvertisedAddress("localhost");
    createCluster(bkEnsemble.getZkClient(), config1);
    pulsar1 = new PulsarService(config1);
    pulsar1.start();

    primaryHost = String.format("%s:%d", "localhost", pulsar1.getListenPortHTTP().get());
    url1 = new URL("http://127.0.0.1" + ":" + pulsar1.getListenPortHTTP().get());
    admin1 = PulsarAdmin.builder().serviceHttpUrl(url1.toString()).build();

    // Start broker 2
    ServiceConfiguration config2 = new ServiceConfiguration();
    config2.setLoadManagerClassName(ModularLoadManagerImpl.class.getName());
    config2.setClusterName("use");
    config2.setWebServicePort(Optional.of(0));
    config2.setZookeeperServers("127.0.0.1" + ":" + bkEnsemble.getZookeeperPort());
    config2.setBrokerServicePort(Optional.of(0));
    config2.setFailureDomainsEnabled(true);
    config2.setAdvertisedAddress("localhost");
    pulsar2 = new PulsarService(config2);
    pulsar2.start();

    secondaryHost = String.format("%s:%d", "localhost", pulsar2.getListenPortHTTP().get());

    url2 = new URL("http://127.0.0.1" + ":" + config2.getWebServicePort().get());
    admin2 = PulsarAdmin.builder().serviceHttpUrl(url2.toString()).build();

    primaryLoadManager = (ModularLoadManagerImpl) getField(pulsar1.getLoadManager().get(), "loadManager");
    secondaryLoadManager = (ModularLoadManagerImpl) getField(pulsar2.getLoadManager().get(), "loadManager");
    nsFactory = new NamespaceBundleFactory(pulsar1, Hashing.crc32());
    Thread.sleep(100);
}
 
Example 5
Source File: LoadBalancerTest.java    From pulsar with Apache License 2.0 4 votes vote down vote up
@BeforeMethod
void setup() throws Exception {
    // Start local bookkeeper ensemble
    bkEnsemble = new LocalBookkeeperEnsemble(3, 0, () -> 0);
    bkEnsemble.start();
    ZkUtils.createFullPathOptimistic(bkEnsemble.getZkClient(),
            SimpleLoadManagerImpl.LOADBALANCER_DYNAMIC_SETTING_STRATEGY_ZPATH,
            "{\"loadBalancerStrategy\":\"leastLoadedServer\"}".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);

    final String localhost = "localhost";
    // start brokers
    for (int i = 0; i < BROKER_COUNT; i++) {


        ServiceConfiguration config = new ServiceConfiguration();
        config.setBrokerServicePort(Optional.ofNullable(brokerNativeBrokerPorts[i]));
        config.setClusterName("use");
        config.setAdvertisedAddress(localhost);
        config.setAdvertisedAddress("localhost");
        config.setWebServicePort(Optional.of(0));
        config.setBrokerServicePortTls(Optional.of(0));
        config.setWebServicePortTls(Optional.of(0));
        config.setZookeeperServers("127.0.0.1" + ":" + bkEnsemble.getZookeeperPort());
        config.setBrokerServicePort(Optional.of(0));
        config.setLoadManagerClassName(SimpleLoadManagerImpl.class.getName());
        config.setAdvertisedAddress(localhost+i);
        config.setLoadBalancerEnabled(false);

        pulsarServices[i] = new PulsarService(config);
        pulsarServices[i].start();
        brokerWebServicePorts[i] = pulsarServices[i].getListenPortHTTP().get();
        brokerNativeBrokerPorts[i] = pulsarServices[i].getBrokerListenPort().get();

        brokerUrls[i] = new URL("http://127.0.0.1" + ":" + brokerWebServicePorts[i]);
        lookupAddresses[i] = pulsarServices[i].getAdvertisedAddress() + ":" + pulsarServices[i].getListenPortHTTP().get();
        pulsarAdmins[i] = PulsarAdmin.builder().serviceHttpUrl(brokerUrls[i].toString()).build();
    }

    createNamespacePolicies(pulsarServices[0]);

    Thread.sleep(100);
}