You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2018/10/05 07:48:33 UTC

[GitHub] sijie closed pull request #2722: local function-worker use localhost broker service url

sijie closed pull request #2722: local function-worker use localhost broker service url
URL: https://github.com/apache/pulsar/pull/2722
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/PulsarBrokerStarter.java b/pulsar-broker/src/main/java/org/apache/pulsar/PulsarBrokerStarter.java
index 42e5f6ee55..98ed15a27c 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/PulsarBrokerStarter.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/PulsarBrokerStarter.java
@@ -145,12 +145,13 @@ private static boolean argsContains(String[] args, String arg) {
                 }
                 // worker talks to local broker
                 boolean useTls = workerConfig.isUseTls();
-                String pulsarServiceUrl = useTls && isNotBlank(PulsarService.brokerUrlTls(brokerConfig))
-                        ? PulsarService.brokerUrlTls(brokerConfig)
-                        : PulsarService.brokerUrl(brokerConfig);
-                String webServiceUrl = useTls && isNotBlank(PulsarService.webAddressTls(brokerConfig))
-                        ? PulsarService.webAddressTls(brokerConfig)
-                        : PulsarService.webAddress(brokerConfig);
+                String localhost = "127.0.0.1";
+                String pulsarServiceUrl = useTls
+                        ? PulsarService.brokerUrlTls(localhost, brokerConfig.getBrokerServicePortTls())
+                        : PulsarService.brokerUrl(localhost, brokerConfig.getBrokerServicePort());
+                String webServiceUrl = useTls
+                        ? PulsarService.webAddressTls(localhost, brokerConfig.getWebServicePortTls())
+                        : PulsarService.webAddress(localhost, brokerConfig.getWebServicePort());
                 workerConfig.setPulsarServiceUrl(pulsarServiceUrl);
                 workerConfig.setPulsarWebServiceUrl(webServiceUrl);
                 String hostname = ServiceConfigurationUtils.getDefaultOrConfiguredAddress(
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 ab565a5d83..63460c7634 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
@@ -826,29 +826,45 @@ public static String advertisedAddress(ServiceConfiguration config) {
     }
 
     public static String brokerUrl(ServiceConfiguration config) {
-        return "pulsar://" + advertisedAddress(config) + ":" + config.getBrokerServicePort();
+        return brokerUrl(advertisedAddress(config), config.getBrokerServicePort());
+    }
+
+    public static String brokerUrl(String host, int port) {
+        return String.format("pulsar://%s:%d", host, port);
     }
 
     public static String brokerUrlTls(ServiceConfiguration config) {
         if (config.isTlsEnabled()) {
-            return "pulsar+ssl://" + advertisedAddress(config) + ":" + config.getBrokerServicePortTls();
+            return brokerUrlTls(advertisedAddress(config), config.getBrokerServicePortTls());
         } else {
             return "";
         }
     }
 
+    public static String brokerUrlTls(String host, int port) {
+        return String.format("pulsar+ssl://%s:%d", host, port);
+    }
+
     public static String webAddress(ServiceConfiguration config) {
-        return String.format("http://%s:%d", advertisedAddress(config), config.getWebServicePort());
+        return webAddress(advertisedAddress(config), config.getWebServicePort());
+    }
+
+    public static String webAddress(String host, int port) {
+        return String.format("http://%s:%d", host, port);
     }
 
     public static String webAddressTls(ServiceConfiguration config) {
         if (config.isTlsEnabled()) {
-            return String.format("https://%s:%d", advertisedAddress(config), config.getWebServicePortTls());
+            return webAddressTls(advertisedAddress(config), config.getWebServicePortTls());
         } else {
             return "";
         }
     }
 
+    public static String webAddressTls(String host, int port) {
+        return String.format("https://%s:%d", host, port);
+    }
+
     public String getBindAddress() {
         return bindAddress;
     }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services