You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by GitBox <gi...@apache.org> on 2022/06/02 02:16:20 UTC

[GitHub] [incubator-inlong] healchow commented on a diff in pull request #4479: [INLONG-4468][Manager] Use config url to create pulsar admin instead of use pulsar dns

healchow commented on code in PR #4479:
URL: https://github.com/apache/incubator-inlong/pull/4479#discussion_r887439823


##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/mq/CreatePulsarSubscriptionTaskListener.java:
##########
@@ -87,28 +88,29 @@ public ListenerResult listen(WorkflowContext context) throws WorkflowListenerExc
             topicBean.setTenant(tenant);
             topicBean.setNamespace(namespace);
             topicBean.setTopicName(topic);
-            List<String> pulsarClusters = PulsarUtils.getPulsarClusters(globalPulsarAdmin);
 
-            // Create a subscription in the Pulsar cluster (cross-region), you need to ensure that the Topic exists
-            for (String cluster : pulsarClusters) {
-                String serviceUrl = PulsarUtils.getServiceUrl(globalPulsarAdmin, cluster);
-                PulsarClusterInfo pulsarClusterInfo = PulsarClusterInfo.builder()
-                        .token(globalCluster.getToken()).adminUrl(serviceUrl).build();
-                try (PulsarAdmin pulsarAdmin = PulsarUtils.getPulsarAdmin(pulsarClusterInfo)) {
-                    boolean exist = pulsarOptService.topicIsExists(pulsarAdmin, tenant, namespace, topic);
-                    if (!exist) {
-                        String fullTopic = tenant + "/" + namespace + "/" + topic;
-                        log.error("topic={} not exists in {}", fullTopic, pulsarAdmin.getServiceUrl());
-                        throw new BusinessException("topic=" + fullTopic + " not exists in " + serviceUrl);
-                    }
+            // Create a subscription in the Pulsar cluster, you need to ensure that the Topic exists
+            try {
+                boolean exist = pulsarOptService.topicIsExists(pulsarAdmin, tenant, namespace, topic);
+                if (!exist) {
+                    String fullTopic = tenant + "/" + namespace + "/" + topic;
+                    String serviceUrl = pulsarClusterInfo.getAdminUrl();
+                    log.error("topic={} not exists in {}", fullTopic, serviceUrl);
+                    throw new BusinessException("topic=" + fullTopic + " not exists in " + serviceUrl);
+                }
 
-                    // Consumer naming rules: sortAppName_topicName_consumer_group
-                    String subscription = clusterBean.getAppName() + "_" + topic + "_consumer_group";
-                    pulsarOptService.createSubscription(pulsarAdmin, topicBean, subscription);
+                // Consumer naming rules: sortAppName_topicName_consumer_group
+                String subscription = clusterBean.getAppName() + "_" + topic + "_consumer_group";
+                pulsarOptService.createSubscription(pulsarAdmin, topicBean, subscription);
 
-                    // Insert the consumption data into the consumption table
-                    consumptionService.saveSortConsumption(groupInfo, topic, subscription);
-                }
+                // Insert the consumption data into the consumption table
+                consumptionService.saveSortConsumption(groupInfo, topic, subscription);
+            } catch (PulsarAdminException e) {

Review Comment:
   The `PulsarAdminException` and `PulsarAdminException` can write in one line as follows:
   
   ```
   catch (PulsarAdminException | BusinessException e)
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org