|
18 | 18 | import static org.apache.commons.lang3.StringUtils.isBlank;
|
19 | 19 |
|
20 | 20 | import java.io.FileInputStream;
|
| 21 | +import java.net.URI; |
21 | 22 | import java.net.URL;
|
22 | 23 |
|
23 | 24 | import org.slf4j.Logger;
|
|
29 | 30 | import com.google.common.collect.Sets;
|
30 | 31 | import com.yahoo.pulsar.broker.PulsarService;
|
31 | 32 | import com.yahoo.pulsar.broker.ServiceConfiguration;
|
| 33 | +import com.yahoo.pulsar.broker.ServiceConfigurationUtils; |
32 | 34 | import com.yahoo.pulsar.client.admin.PulsarAdmin;
|
33 | 35 | import com.yahoo.pulsar.client.admin.PulsarAdminException;
|
34 | 36 | import com.yahoo.pulsar.common.configuration.PulsarConfigurationLoader;
|
@@ -70,6 +72,9 @@ public class PulsarStandaloneStarter {
|
70 | 72 | @Parameter(names = { "--only-broker" }, description = "Only start Pulsar broker service (no ZK, BK)")
|
71 | 73 | private boolean onlyBroker = false;
|
72 | 74 |
|
| 75 | + @Parameter(names = { "-a", "--advertised-address" }, description = "Standalone broker advertised address") |
| 76 | + private String advertisedAddress = null; |
| 77 | + |
73 | 78 | @Parameter(names = { "-h", "--help" }, description = "Show this help message")
|
74 | 79 | private boolean help = false;
|
75 | 80 |
|
@@ -103,6 +108,16 @@ public PulsarStandaloneStarter(String[] args) throws Exception {
|
103 | 108 | config.setGlobalZookeeperServers("127.0.0.1:" + zkPort);
|
104 | 109 | config.setWebSocketServiceEnabled(true);
|
105 | 110 |
|
| 111 | + if (advertisedAddress != null) { |
| 112 | + // Use advertised address from command line |
| 113 | + config.setAdvertisedAddress(advertisedAddress); |
| 114 | + } else if (isBlank(config.getAdvertisedAddress())) { |
| 115 | + // Use advertised address as local hostname |
| 116 | + config.setAdvertisedAddress(ServiceConfigurationUtils.unsafeLocalhostResolve()); |
| 117 | + } else { |
| 118 | + // Use advertised address from config file |
| 119 | + } |
| 120 | + |
106 | 121 | Runtime.getRuntime().addShutdownHook(new Thread() {
|
107 | 122 | public void run() {
|
108 | 123 | try {
|
@@ -143,15 +158,22 @@ void start() throws Exception {
|
143 | 158 | broker.start();
|
144 | 159 |
|
145 | 160 | // Create a sample namespace
|
146 |
| - URL url = new URL("http://127.0.0.1:" + config.getWebServicePort()); |
147 |
| - admin = new PulsarAdmin(url, config.getBrokerClientAuthenticationPlugin(), |
| 161 | + URL webServiceUrl = new URL( |
| 162 | + String.format("http://%s:%d", config.getAdvertisedAddress(), config.getWebServicePort())); |
| 163 | + String brokerServiceUrl = String.format("pulsar://%s:%d", config.getAdvertisedAddress(), |
| 164 | + config.getBrokerServicePort()); |
| 165 | + admin = new PulsarAdmin(webServiceUrl, config.getBrokerClientAuthenticationPlugin(), |
148 | 166 | config.getBrokerClientAuthenticationParameters());
|
149 | 167 | String property = "sample";
|
150 | 168 | String cluster = config.getClusterName();
|
151 | 169 | String namespace = property + "/" + cluster + "/ns1";
|
152 | 170 | try {
|
| 171 | + ClusterData clusterData = new ClusterData(webServiceUrl.toString(), null /* serviceUrlTls */, |
| 172 | + brokerServiceUrl, null /* brokerServiceUrlTls */); |
153 | 173 | if (!admin.clusters().getClusters().contains(cluster)) {
|
154 |
| - admin.clusters().createCluster(cluster, new ClusterData(url.toString())); |
| 174 | + admin.clusters().createCluster(cluster, clusterData); |
| 175 | + } else { |
| 176 | + admin.clusters().updateCluster(cluster, clusterData); |
155 | 177 | }
|
156 | 178 |
|
157 | 179 | if (!admin.properties().getProperties().contains(property)) {
|
|
0 commit comments