This is an automated email from the ASF dual-hosted git repository. guangning pushed a commit to branch branch-2.5 in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit 4624d163416027017fac0fff73e1e066fdcb21ef Author: Sijie Guo <[email protected]> AuthorDate: Thu Jan 23 23:02:35 2020 -0800 [Websocket] Websocket doesn't set the correct cluster data (#6102) *Motivation* Fixes #5997 Fixes #6079 A regression was introduced in #5486. If websocket service as running as part of pulsar standalone, the cluster data is set with null service urls. This causes service url is not set correctly in the pulsar client and an illegal argument exception ("Param serviceUrl must not be blank.") will be thrown. *Modifications* 1. Pass `null` when constructing the websocket service. So the local cluster data can be refreshed when creating pulsar client. 2. Set the cluster data after both broker service and web service started and ports are allocated. --- .../src/main/java/org/apache/pulsar/broker/PulsarService.java | 10 +++++++--- .../java/org/apache/pulsar/websocket/WebSocketService.java | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java index fd169fe..ff7ba47 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java @@ -427,9 +427,7 @@ public class PulsarService implements AutoCloseable { if (config.isWebSocketServiceEnabled()) { // Use local broker address to avoid different IP address when using a VIP for service discovery - this.webSocketService = new WebSocketService( - new ClusterData(webServiceAddress, webServiceAddressTls, brokerServiceUrl, brokerServiceUrlTls), - config); + this.webSocketService = new WebSocketService(null, config); this.webSocketService.start(); final WebSocketServlet producerWebSocketServlet = new WebSocketProducerServlet(webSocketService); @@ -466,6 +464,12 @@ public class PulsarService implements AutoCloseable { this.brokerServiceUrl = brokerUrl(config); this.brokerServiceUrlTls = brokerUrlTls(config); + if (null != this.webSocketService) { + ClusterData clusterData = + new ClusterData(webServiceAddress, webServiceAddressTls, brokerServiceUrl, brokerServiceUrlTls); + this.webSocketService.setLocalCluster(clusterData); + } + // needs load management service this.startNamespaceService(); diff --git a/pulsar-websocket/src/main/java/org/apache/pulsar/websocket/WebSocketService.java b/pulsar-websocket/src/main/java/org/apache/pulsar/websocket/WebSocketService.java index 79cd436..062af7e 100644 --- a/pulsar-websocket/src/main/java/org/apache/pulsar/websocket/WebSocketService.java +++ b/pulsar-websocket/src/main/java/org/apache/pulsar/websocket/WebSocketService.java @@ -30,6 +30,7 @@ import java.util.concurrent.TimeUnit; import javax.servlet.ServletException; import javax.websocket.DeploymentException; +import lombok.Setter; import org.apache.bookkeeper.common.util.OrderedScheduler; import org.apache.pulsar.broker.PulsarServerException; import org.apache.pulsar.broker.ServiceConfiguration; @@ -77,6 +78,7 @@ public class WebSocketService implements Closeable { private ServiceConfiguration config; private ConfigurationCacheService configurationCacheService; + @Setter private ClusterData localCluster; private final ConcurrentOpenHashMap<String, ConcurrentOpenHashSet<ProducerHandler>> topicProducerMap; private final ConcurrentOpenHashMap<String, ConcurrentOpenHashSet<ConsumerHandler>> topicConsumerMap;
