Skip to content

Commit

Permalink
[Websocket] Websocket doesn't set the correct cluster data (apache#6102
Browse files Browse the repository at this point in the history
)

*Motivation*

Fixes apache#5997
Fixes apache#6079

A regression was introduced in apache#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.
  • Loading branch information
sijie authored and tuteng committed Feb 23, 2020
1 parent b70b15c commit 4624d16
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 4624d16

Please sign in to comment.