Search in sources :

Example 1 with WebSocketService

use of org.apache.pulsar.websocket.WebSocketService in project incubator-pulsar by apache.

the class ProxyPublishConsumeWithoutZKTest method setup.

@BeforeMethod
public void setup() throws Exception {
    super.internalSetup();
    super.producerBaseSetup();
    port = PortManager.nextFreePort();
    WebSocketProxyConfiguration config = new WebSocketProxyConfiguration();
    config.setWebServicePort(port);
    config.setClusterName("use");
    config.setServiceUrl(pulsar.getWebServiceAddress());
    config.setServiceUrlTls(pulsar.getWebServiceAddressTls());
    service = spy(new WebSocketService(config));
    doReturn(mockZooKeeperClientFactory).when(service).getZooKeeperClientFactory();
    proxyServer = new ProxyServer(config);
    WebSocketServiceStarter.start(proxyServer, service);
    log.info("Proxy Server Started");
}
Also used : WebSocketProxyConfiguration(org.apache.pulsar.websocket.service.WebSocketProxyConfiguration) WebSocketService(org.apache.pulsar.websocket.WebSocketService) ProxyServer(org.apache.pulsar.websocket.service.ProxyServer) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with WebSocketService

use of org.apache.pulsar.websocket.WebSocketService in project incubator-pulsar by apache.

the class WebSocketServiceStarter method main.

public static void main(String[] args) throws Exception {
    checkArgument(args.length == 1, "Need to specify a configuration file");
    try {
        // load config file and start proxy service
        String configFile = args[0];
        log.info("Loading configuration from {}", configFile);
        WebSocketProxyConfiguration config = PulsarConfigurationLoader.create(configFile, WebSocketProxyConfiguration.class);
        ProxyServer proxyServer = new ProxyServer(config);
        WebSocketService service = new WebSocketService(config);
        start(proxyServer, service);
    } catch (Exception e) {
        log.error("Failed to start WebSocket service", e);
        Runtime.getRuntime().halt(1);
    }
}
Also used : WebSocketService(org.apache.pulsar.websocket.WebSocketService)

Example 3 with WebSocketService

use of org.apache.pulsar.websocket.WebSocketService in project incubator-pulsar by apache.

the class LookupProtocolTest method httpLookupTest.

@Test(timeOut = 10000)
public void httpLookupTest() throws Exception {
    WebSocketProxyConfiguration conf = new WebSocketProxyConfiguration();
    conf.setServiceUrl("http://localhost:8080");
    conf.setServiceUrlTls("https://localhost:8443");
    WebSocketService service = new WebSocketService(conf);
    PulsarClientImpl testClient = (PulsarClientImpl) service.getPulsarClient();
    Field lookupField = PulsarClientImpl.class.getDeclaredField("lookup");
    lookupField.setAccessible(true);
    Assert.assertEquals(lookupField.get(testClient).getClass().getName(), "org.apache.pulsar.client.impl.HttpLookupService");
    Assert.assertFalse(testClient.getConfiguration().isUseTls());
    service.close();
}
Also used : Field(java.lang.reflect.Field) WebSocketProxyConfiguration(org.apache.pulsar.websocket.service.WebSocketProxyConfiguration) WebSocketService(org.apache.pulsar.websocket.WebSocketService) PulsarClientImpl(org.apache.pulsar.client.impl.PulsarClientImpl) Test(org.testng.annotations.Test)

Example 4 with WebSocketService

use of org.apache.pulsar.websocket.WebSocketService in project incubator-pulsar by apache.

the class LookupProtocolTest method httpsLookupTest.

@Test(timeOut = 10000)
public void httpsLookupTest() throws Exception {
    WebSocketProxyConfiguration conf = new WebSocketProxyConfiguration();
    conf.setServiceUrl("http://localhost:8080");
    conf.setServiceUrlTls("https://localhost:8443");
    conf.setBrokerServiceUrl("pulsar://localhost:6650");
    conf.setTlsEnabled(true);
    WebSocketService service = new WebSocketService(conf);
    PulsarClientImpl testClient = (PulsarClientImpl) service.getPulsarClient();
    Field lookupField = PulsarClientImpl.class.getDeclaredField("lookup");
    lookupField.setAccessible(true);
    Assert.assertEquals(lookupField.get(testClient).getClass().getName(), "org.apache.pulsar.client.impl.HttpLookupService");
    Assert.assertTrue(testClient.getConfiguration().isUseTls());
    service.close();
}
Also used : Field(java.lang.reflect.Field) WebSocketProxyConfiguration(org.apache.pulsar.websocket.service.WebSocketProxyConfiguration) WebSocketService(org.apache.pulsar.websocket.WebSocketService) PulsarClientImpl(org.apache.pulsar.client.impl.PulsarClientImpl) Test(org.testng.annotations.Test)

Example 5 with WebSocketService

use of org.apache.pulsar.websocket.WebSocketService in project incubator-pulsar by apache.

the class LookupProtocolTest method binaryTlsLookupTest.

@Test(timeOut = 10000)
public void binaryTlsLookupTest() throws Exception {
    WebSocketProxyConfiguration conf = new WebSocketProxyConfiguration();
    conf.setServiceUrl("http://localhost:8080");
    conf.setServiceUrlTls("https://localhost:8443");
    conf.setBrokerServiceUrl("pulsar://localhost:6650");
    conf.setBrokerServiceUrlTls("pulsar+ssl://localhost:6651");
    conf.setTlsEnabled(true);
    WebSocketService service = new WebSocketService(conf);
    PulsarClientImpl testClient = (PulsarClientImpl) service.getPulsarClient();
    Field lookupField = PulsarClientImpl.class.getDeclaredField("lookup");
    lookupField.setAccessible(true);
    Assert.assertEquals(lookupField.get(testClient).getClass().getName(), "org.apache.pulsar.client.impl.BinaryProtoLookupService");
    Assert.assertTrue(testClient.getConfiguration().isUseTls());
    service.close();
}
Also used : Field(java.lang.reflect.Field) WebSocketProxyConfiguration(org.apache.pulsar.websocket.service.WebSocketProxyConfiguration) WebSocketService(org.apache.pulsar.websocket.WebSocketService) PulsarClientImpl(org.apache.pulsar.client.impl.PulsarClientImpl) Test(org.testng.annotations.Test)

Aggregations

WebSocketService (org.apache.pulsar.websocket.WebSocketService)11 WebSocketProxyConfiguration (org.apache.pulsar.websocket.service.WebSocketProxyConfiguration)9 Field (java.lang.reflect.Field)4 PulsarClientImpl (org.apache.pulsar.client.impl.PulsarClientImpl)4 ProxyServer (org.apache.pulsar.websocket.service.ProxyServer)4 BeforeMethod (org.testng.annotations.BeforeMethod)4 Test (org.testng.annotations.Test)4 IOException (java.io.IOException)1 URI (java.net.URI)1 LeaderElectionService (org.apache.pulsar.broker.loadbalance.LeaderElectionService)1 LeaderListener (org.apache.pulsar.broker.loadbalance.LeaderElectionService.LeaderListener)1 LoadResourceQuotaUpdaterTask (org.apache.pulsar.broker.loadbalance.LoadResourceQuotaUpdaterTask)1 LoadSheddingTask (org.apache.pulsar.broker.loadbalance.LoadSheddingTask)1 BrokerService (org.apache.pulsar.broker.service.BrokerService)1 MetricsGenerator (org.apache.pulsar.broker.stats.MetricsGenerator)1 PrometheusMetricsServlet (org.apache.pulsar.broker.stats.prometheus.PrometheusMetricsServlet)1 WebService (org.apache.pulsar.broker.web.WebService)1 AuthenticationTls (org.apache.pulsar.client.impl.auth.AuthenticationTls)1 ClusterData (org.apache.pulsar.common.policies.data.ClusterData)1 WebSocketConsumerServlet (org.apache.pulsar.websocket.WebSocketConsumerServlet)1