Skip to content

Commit

Permalink
[Websocket] Websocket doesn't set the correct cluster data (#6102)
Browse files Browse the repository at this point in the history
*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.

(cherry picked from commit 49a9897)
  • Loading branch information
sijie authored and tuteng committed Apr 13, 2020
1 parent acdd987 commit 13b65f1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,7 @@ public Boolean get() {

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);
Expand Down Expand Up @@ -466,6 +464,12 @@ public Boolean get() {
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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 13b65f1

Please sign in to comment.