Search in sources :

Example 1 with WebSocketPingPongServlet

use of org.apache.pulsar.websocket.WebSocketPingPongServlet in project pulsar by apache.

the class WebSocketServiceStarter method start.

public static void start(ProxyServer proxyServer, WebSocketService service) throws Exception {
    proxyServer.addWebSocketServlet(WebSocketProducerServlet.SERVLET_PATH, new WebSocketProducerServlet(service));
    proxyServer.addWebSocketServlet(WebSocketConsumerServlet.SERVLET_PATH, new WebSocketConsumerServlet(service));
    proxyServer.addWebSocketServlet(WebSocketReaderServlet.SERVLET_PATH, new WebSocketReaderServlet(service));
    proxyServer.addWebSocketServlet(WebSocketPingPongServlet.SERVLET_PATH, new WebSocketPingPongServlet(service));
    proxyServer.addWebSocketServlet(WebSocketProducerServlet.SERVLET_PATH_V2, new WebSocketProducerServlet(service));
    proxyServer.addWebSocketServlet(WebSocketConsumerServlet.SERVLET_PATH_V2, new WebSocketConsumerServlet(service));
    proxyServer.addWebSocketServlet(WebSocketReaderServlet.SERVLET_PATH_V2, new WebSocketReaderServlet(service));
    proxyServer.addWebSocketServlet(WebSocketPingPongServlet.SERVLET_PATH_V2, new WebSocketPingPongServlet(service));
    proxyServer.addRestResources(ADMIN_PATH_V1, WebSocketProxyStatsV1.class.getPackage().getName(), ATTRIBUTE_PROXY_SERVICE_NAME, service);
    proxyServer.addRestResources(ADMIN_PATH_V2, WebSocketProxyStatsV2.class.getPackage().getName(), ATTRIBUTE_PROXY_SERVICE_NAME, service);
    proxyServer.addRestResources("/", VipStatus.class.getPackage().getName(), VipStatus.ATTRIBUTE_STATUS_FILE_PATH, service.getConfig().getStatusFilePath());
    proxyServer.start();
    service.start();
}
Also used : WebSocketPingPongServlet(org.apache.pulsar.websocket.WebSocketPingPongServlet) WebSocketReaderServlet(org.apache.pulsar.websocket.WebSocketReaderServlet) WebSocketProducerServlet(org.apache.pulsar.websocket.WebSocketProducerServlet) WebSocketConsumerServlet(org.apache.pulsar.websocket.WebSocketConsumerServlet)

Example 2 with WebSocketPingPongServlet

use of org.apache.pulsar.websocket.WebSocketPingPongServlet in project pulsar by yahoo.

the class ProxyServiceStarter method addWebServerHandlers.

public static void addWebServerHandlers(WebServer server, ProxyConfiguration config, ProxyService service, BrokerDiscoveryProvider discoveryProvider) throws Exception {
    if (service != null) {
        PrometheusMetricsServlet metricsServlet = service.getMetricsServlet();
        if (metricsServlet != null) {
            server.addServlet("/metrics", new ServletHolder(metricsServlet), Collections.emptyList(), config.isAuthenticateMetricsEndpoint());
        }
    }
    server.addRestResources("/", VipStatus.class.getPackage().getName(), VipStatus.ATTRIBUTE_STATUS_FILE_PATH, config.getStatusFilePath());
    server.addRestResources("/proxy-stats", ProxyStats.class.getPackage().getName(), ProxyStats.ATTRIBUTE_PULSAR_PROXY_NAME, service);
    AdminProxyHandler adminProxyHandler = new AdminProxyHandler(config, discoveryProvider);
    ServletHolder servletHolder = new ServletHolder(adminProxyHandler);
    servletHolder.setInitParameter("preserveHost", "true");
    server.addServlet("/admin", servletHolder);
    server.addServlet("/lookup", servletHolder);
    for (ProxyConfiguration.HttpReverseProxyConfig revProxy : config.getHttpReverseProxyConfigs()) {
        log.debug("Adding reverse proxy with config {}", revProxy);
        ServletHolder proxyHolder = new ServletHolder(ProxyServlet.Transparent.class);
        proxyHolder.setInitParameter("proxyTo", revProxy.getProxyTo());
        proxyHolder.setInitParameter("prefix", "/");
        server.addServlet(revProxy.getPath(), proxyHolder);
    }
    // add proxy additional servlets
    if (service != null && service.getProxyAdditionalServlets() != null) {
        Collection<AdditionalServletWithClassLoader> additionalServletCollection = service.getProxyAdditionalServlets().getServlets().values();
        for (AdditionalServletWithClassLoader servletWithClassLoader : additionalServletCollection) {
            servletWithClassLoader.loadConfig(config);
            server.addServlet(servletWithClassLoader.getBasePath(), servletWithClassLoader.getServletHolder(), Collections.emptyList(), config.isAuthenticationEnabled());
            log.info("proxy add additional servlet basePath {} ", servletWithClassLoader.getBasePath());
        }
    }
    if (config.isWebSocketServiceEnabled()) {
        // add WebSocket servlet
        // Use local broker address to avoid different IP address when using a VIP for service discovery
        ServiceConfiguration serviceConfiguration = PulsarConfigurationLoader.convertFrom(config);
        serviceConfiguration.setBrokerClientTlsEnabled(config.isTlsEnabledWithBroker());
        WebSocketService webSocketService = new WebSocketService(createClusterData(config), serviceConfiguration);
        webSocketService.start();
        final WebSocketServlet producerWebSocketServlet = new WebSocketProducerServlet(webSocketService);
        server.addServlet(WebSocketProducerServlet.SERVLET_PATH, new ServletHolder(producerWebSocketServlet));
        server.addServlet(WebSocketProducerServlet.SERVLET_PATH_V2, new ServletHolder(producerWebSocketServlet));
        final WebSocketServlet consumerWebSocketServlet = new WebSocketConsumerServlet(webSocketService);
        server.addServlet(WebSocketConsumerServlet.SERVLET_PATH, new ServletHolder(consumerWebSocketServlet));
        server.addServlet(WebSocketConsumerServlet.SERVLET_PATH_V2, new ServletHolder(consumerWebSocketServlet));
        final WebSocketServlet readerWebSocketServlet = new WebSocketReaderServlet(webSocketService);
        server.addServlet(WebSocketReaderServlet.SERVLET_PATH, new ServletHolder(readerWebSocketServlet));
        server.addServlet(WebSocketReaderServlet.SERVLET_PATH_V2, new ServletHolder(readerWebSocketServlet));
        final WebSocketServlet pingPongWebSocketServlet = new WebSocketPingPongServlet(webSocketService);
        server.addServlet(WebSocketPingPongServlet.SERVLET_PATH, new ServletHolder(pingPongWebSocketServlet));
        server.addServlet(WebSocketPingPongServlet.SERVLET_PATH_V2, new ServletHolder(pingPongWebSocketServlet));
    }
}
Also used : WebSocketReaderServlet(org.apache.pulsar.websocket.WebSocketReaderServlet) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ProxyServlet(org.eclipse.jetty.proxy.ProxyServlet) WebSocketServlet(org.eclipse.jetty.websocket.servlet.WebSocketServlet) WebSocketProducerServlet(org.apache.pulsar.websocket.WebSocketProducerServlet) WebSocketConsumerServlet(org.apache.pulsar.websocket.WebSocketConsumerServlet) WebSocketPingPongServlet(org.apache.pulsar.websocket.WebSocketPingPongServlet) PrometheusMetricsServlet(org.apache.pulsar.broker.stats.prometheus.PrometheusMetricsServlet) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) WebSocketService(org.apache.pulsar.websocket.WebSocketService) AdditionalServletWithClassLoader(org.apache.pulsar.broker.web.plugin.servlet.AdditionalServletWithClassLoader)

Example 3 with WebSocketPingPongServlet

use of org.apache.pulsar.websocket.WebSocketPingPongServlet in project pulsar by yahoo.

the class WebSocketServiceStarter method start.

public static void start(ProxyServer proxyServer, WebSocketService service) throws Exception {
    proxyServer.addWebSocketServlet(WebSocketProducerServlet.SERVLET_PATH, new WebSocketProducerServlet(service));
    proxyServer.addWebSocketServlet(WebSocketConsumerServlet.SERVLET_PATH, new WebSocketConsumerServlet(service));
    proxyServer.addWebSocketServlet(WebSocketReaderServlet.SERVLET_PATH, new WebSocketReaderServlet(service));
    proxyServer.addWebSocketServlet(WebSocketPingPongServlet.SERVLET_PATH, new WebSocketPingPongServlet(service));
    proxyServer.addWebSocketServlet(WebSocketProducerServlet.SERVLET_PATH_V2, new WebSocketProducerServlet(service));
    proxyServer.addWebSocketServlet(WebSocketConsumerServlet.SERVLET_PATH_V2, new WebSocketConsumerServlet(service));
    proxyServer.addWebSocketServlet(WebSocketReaderServlet.SERVLET_PATH_V2, new WebSocketReaderServlet(service));
    proxyServer.addWebSocketServlet(WebSocketPingPongServlet.SERVLET_PATH_V2, new WebSocketPingPongServlet(service));
    proxyServer.addRestResources(ADMIN_PATH_V1, WebSocketProxyStatsV1.class.getPackage().getName(), ATTRIBUTE_PROXY_SERVICE_NAME, service);
    proxyServer.addRestResources(ADMIN_PATH_V2, WebSocketProxyStatsV2.class.getPackage().getName(), ATTRIBUTE_PROXY_SERVICE_NAME, service);
    proxyServer.addRestResources("/", VipStatus.class.getPackage().getName(), VipStatus.ATTRIBUTE_STATUS_FILE_PATH, service.getConfig().getStatusFilePath());
    proxyServer.start();
    service.start();
}
Also used : WebSocketPingPongServlet(org.apache.pulsar.websocket.WebSocketPingPongServlet) WebSocketReaderServlet(org.apache.pulsar.websocket.WebSocketReaderServlet) WebSocketProducerServlet(org.apache.pulsar.websocket.WebSocketProducerServlet) WebSocketConsumerServlet(org.apache.pulsar.websocket.WebSocketConsumerServlet)

Example 4 with WebSocketPingPongServlet

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

the class ProxyServiceStarter method addWebServerHandlers.

public static void addWebServerHandlers(WebServer server, ProxyConfiguration config, ProxyService service, BrokerDiscoveryProvider discoveryProvider) throws Exception {
    if (service != null) {
        PrometheusMetricsServlet metricsServlet = service.getMetricsServlet();
        if (metricsServlet != null) {
            server.addServlet("/metrics", new ServletHolder(metricsServlet), Collections.emptyList(), config.isAuthenticateMetricsEndpoint());
        }
    }
    server.addRestResources("/", VipStatus.class.getPackage().getName(), VipStatus.ATTRIBUTE_STATUS_FILE_PATH, config.getStatusFilePath());
    server.addRestResources("/proxy-stats", ProxyStats.class.getPackage().getName(), ProxyStats.ATTRIBUTE_PULSAR_PROXY_NAME, service);
    AdminProxyHandler adminProxyHandler = new AdminProxyHandler(config, discoveryProvider);
    ServletHolder servletHolder = new ServletHolder(adminProxyHandler);
    servletHolder.setInitParameter("preserveHost", "true");
    server.addServlet("/admin", servletHolder);
    server.addServlet("/lookup", servletHolder);
    for (ProxyConfiguration.HttpReverseProxyConfig revProxy : config.getHttpReverseProxyConfigs()) {
        log.debug("Adding reverse proxy with config {}", revProxy);
        ServletHolder proxyHolder = new ServletHolder(ProxyServlet.Transparent.class);
        proxyHolder.setInitParameter("proxyTo", revProxy.getProxyTo());
        proxyHolder.setInitParameter("prefix", "/");
        server.addServlet(revProxy.getPath(), proxyHolder);
    }
    // add proxy additional servlets
    if (service != null && service.getProxyAdditionalServlets() != null) {
        Collection<AdditionalServletWithClassLoader> additionalServletCollection = service.getProxyAdditionalServlets().getServlets().values();
        for (AdditionalServletWithClassLoader servletWithClassLoader : additionalServletCollection) {
            servletWithClassLoader.loadConfig(config);
            server.addServlet(servletWithClassLoader.getBasePath(), servletWithClassLoader.getServletHolder(), Collections.emptyList(), config.isAuthenticationEnabled());
            log.info("proxy add additional servlet basePath {} ", servletWithClassLoader.getBasePath());
        }
    }
    if (config.isWebSocketServiceEnabled()) {
        // add WebSocket servlet
        // Use local broker address to avoid different IP address when using a VIP for service discovery
        ServiceConfiguration serviceConfiguration = PulsarConfigurationLoader.convertFrom(config);
        serviceConfiguration.setBrokerClientTlsEnabled(config.isTlsEnabledWithBroker());
        WebSocketService webSocketService = new WebSocketService(createClusterData(config), serviceConfiguration);
        webSocketService.start();
        final WebSocketServlet producerWebSocketServlet = new WebSocketProducerServlet(webSocketService);
        server.addServlet(WebSocketProducerServlet.SERVLET_PATH, new ServletHolder(producerWebSocketServlet));
        server.addServlet(WebSocketProducerServlet.SERVLET_PATH_V2, new ServletHolder(producerWebSocketServlet));
        final WebSocketServlet consumerWebSocketServlet = new WebSocketConsumerServlet(webSocketService);
        server.addServlet(WebSocketConsumerServlet.SERVLET_PATH, new ServletHolder(consumerWebSocketServlet));
        server.addServlet(WebSocketConsumerServlet.SERVLET_PATH_V2, new ServletHolder(consumerWebSocketServlet));
        final WebSocketServlet readerWebSocketServlet = new WebSocketReaderServlet(webSocketService);
        server.addServlet(WebSocketReaderServlet.SERVLET_PATH, new ServletHolder(readerWebSocketServlet));
        server.addServlet(WebSocketReaderServlet.SERVLET_PATH_V2, new ServletHolder(readerWebSocketServlet));
        final WebSocketServlet pingPongWebSocketServlet = new WebSocketPingPongServlet(webSocketService);
        server.addServlet(WebSocketPingPongServlet.SERVLET_PATH, new ServletHolder(pingPongWebSocketServlet));
        server.addServlet(WebSocketPingPongServlet.SERVLET_PATH_V2, new ServletHolder(pingPongWebSocketServlet));
    }
}
Also used : WebSocketReaderServlet(org.apache.pulsar.websocket.WebSocketReaderServlet) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ProxyServlet(org.eclipse.jetty.proxy.ProxyServlet) WebSocketServlet(org.eclipse.jetty.websocket.servlet.WebSocketServlet) WebSocketProducerServlet(org.apache.pulsar.websocket.WebSocketProducerServlet) WebSocketConsumerServlet(org.apache.pulsar.websocket.WebSocketConsumerServlet) WebSocketPingPongServlet(org.apache.pulsar.websocket.WebSocketPingPongServlet) PrometheusMetricsServlet(org.apache.pulsar.broker.stats.prometheus.PrometheusMetricsServlet) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) WebSocketService(org.apache.pulsar.websocket.WebSocketService) AdditionalServletWithClassLoader(org.apache.pulsar.broker.web.plugin.servlet.AdditionalServletWithClassLoader)

Example 5 with WebSocketPingPongServlet

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

the class WebSocketServiceStarter method start.

public static void start(ProxyServer proxyServer, WebSocketService service) throws Exception {
    proxyServer.addWebSocketServlet(WebSocketProducerServlet.SERVLET_PATH, new WebSocketProducerServlet(service));
    proxyServer.addWebSocketServlet(WebSocketConsumerServlet.SERVLET_PATH, new WebSocketConsumerServlet(service));
    proxyServer.addWebSocketServlet(WebSocketReaderServlet.SERVLET_PATH, new WebSocketReaderServlet(service));
    proxyServer.addWebSocketServlet(WebSocketPingPongServlet.SERVLET_PATH, new WebSocketPingPongServlet(service));
    proxyServer.addWebSocketServlet(WebSocketProducerServlet.SERVLET_PATH_V2, new WebSocketProducerServlet(service));
    proxyServer.addWebSocketServlet(WebSocketConsumerServlet.SERVLET_PATH_V2, new WebSocketConsumerServlet(service));
    proxyServer.addWebSocketServlet(WebSocketReaderServlet.SERVLET_PATH_V2, new WebSocketReaderServlet(service));
    proxyServer.addWebSocketServlet(WebSocketPingPongServlet.SERVLET_PATH_V2, new WebSocketPingPongServlet(service));
    proxyServer.addRestResources(ADMIN_PATH_V1, WebSocketProxyStatsV1.class.getPackage().getName(), ATTRIBUTE_PROXY_SERVICE_NAME, service);
    proxyServer.addRestResources(ADMIN_PATH_V2, WebSocketProxyStatsV2.class.getPackage().getName(), ATTRIBUTE_PROXY_SERVICE_NAME, service);
    proxyServer.addRestResources("/", VipStatus.class.getPackage().getName(), VipStatus.ATTRIBUTE_STATUS_FILE_PATH, service.getConfig().getStatusFilePath());
    proxyServer.start();
    service.start();
}
Also used : WebSocketPingPongServlet(org.apache.pulsar.websocket.WebSocketPingPongServlet) WebSocketReaderServlet(org.apache.pulsar.websocket.WebSocketReaderServlet) WebSocketProducerServlet(org.apache.pulsar.websocket.WebSocketProducerServlet) WebSocketConsumerServlet(org.apache.pulsar.websocket.WebSocketConsumerServlet)

Aggregations

WebSocketConsumerServlet (org.apache.pulsar.websocket.WebSocketConsumerServlet)9 WebSocketPingPongServlet (org.apache.pulsar.websocket.WebSocketPingPongServlet)9 WebSocketProducerServlet (org.apache.pulsar.websocket.WebSocketProducerServlet)9 WebSocketReaderServlet (org.apache.pulsar.websocket.WebSocketReaderServlet)9 WebSocketService (org.apache.pulsar.websocket.WebSocketService)6 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)6 WebSocketServlet (org.eclipse.jetty.websocket.servlet.WebSocketServlet)6 ServiceConfiguration (org.apache.pulsar.broker.ServiceConfiguration)3 AdditionalServletWithClassLoader (org.apache.pulsar.broker.web.plugin.servlet.AdditionalServletWithClassLoader)3 ProxyServlet (org.eclipse.jetty.proxy.ProxyServlet)3 PrometheusMetricsServlet (org.apache.pulsar.broker.stats.prometheus.PrometheusMetricsServlet)2 MetricsServlet (io.prometheus.client.exporter.MetricsServlet)1