Skip to content

Commit

Permalink
[pulsar-proxy] add advertised address option for proxy (apache#6942)
Browse files Browse the repository at this point in the history
### Motivation
We are running pulsar-proxy on env where we want to advertise different address that hostname. So, adding advertisedAddress into pulsar-proxy config.
  • Loading branch information
rdhabalia authored May 18, 2020
1 parent 8adfb58 commit 9312d65
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions conf/proxy.conf
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ zooKeeperCacheExpirySeconds=300

### --- Server --- ###

# Hostname or IP address the service advertises to the outside world.
# If not set, the value of `InetAddress.getLocalHost().getHostname()` is used.
advertisedAddress=

# The port to use for server binary Protobuf requests
servicePort=6650

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ public class ProxyConfiguration implements PulsarConfiguration {
)
private String functionWorkerWebServiceURLTLS;

@FieldContext(
category = CATEGORY_SERVER,
doc = "Hostname or IP address the service advertises to the outside world."
+ " If not set, the value of `InetAddress.getLocalHost().getHostname()` is used."
)
private String advertisedAddress;
@FieldContext(
category = CATEGORY_SERVER,
doc = "The port for serving binary protobuf request"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,16 @@
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

import org.apache.commons.lang3.StringUtils;
import org.apache.pulsar.broker.authentication.AuthenticationService;
import org.apache.pulsar.broker.authorization.AuthorizationService;
import org.apache.pulsar.broker.cache.ConfigurationCacheService;
Expand Down Expand Up @@ -189,7 +188,8 @@ public void start() throws Exception {

String hostname;
try {
hostname = InetAddress.getLocalHost().getHostName();
hostname = StringUtils.isNotBlank(proxyConfig.getAdvertisedAddress()) ? proxyConfig.getAdvertisedAddress()
: InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
throw new RuntimeException(e);
}
Expand Down

0 comments on commit 9312d65

Please sign in to comment.