You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@eventmesh.apache.org by GitBox <gi...@apache.org> on 2022/09/10 03:35:48 UTC

[GitHub] [incubator-eventmesh] li-xiao-shuang commented on a diff in pull request #1245: [ISSUE#1244]java sdk add nacos selector

li-xiao-shuang commented on code in PR #1245:
URL: https://github.com/apache/incubator-eventmesh/pull/1245#discussion_r967575171


##########
eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/selector/NacosSelector.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.eventmesh.client.selector;
+
+import org.apache.eventmesh.common.Constants;
+import org.apache.eventmesh.common.utils.PropertiesUtils;
+
+import java.util.Properties;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.alibaba.nacos.api.exception.NacosException;
+import com.alibaba.nacos.api.naming.NamingFactory;
+import com.alibaba.nacos.api.naming.NamingService;
+import com.alibaba.nacos.api.naming.pojo.Instance;
+
+public class NacosSelector implements Selector {
+    private static final Logger logger = LoggerFactory.getLogger(NacosSelector.class);
+    private NamingService namingService;
+
+    public void init() throws Exception {

Review Comment:
   Whether to consider initializing only once



##########
eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/selector/NacosSelector.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.eventmesh.client.selector;
+
+import org.apache.eventmesh.common.Constants;
+import org.apache.eventmesh.common.utils.PropertiesUtils;
+
+import java.util.Properties;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.alibaba.nacos.api.exception.NacosException;
+import com.alibaba.nacos.api.naming.NamingFactory;
+import com.alibaba.nacos.api.naming.NamingService;
+import com.alibaba.nacos.api.naming.pojo.Instance;
+
+public class NacosSelector implements Selector {
+    private static final Logger logger = LoggerFactory.getLogger(NacosSelector.class);
+    private NamingService namingService;
+
+    public void init() throws Exception {
+        try {
+            Properties properties = PropertiesUtils.readPropertiesFile(Constants.CONFIG_FILE_NAME);
+            namingService = NamingFactory.createNamingService(properties.getProperty(Constants.EVENTMESH_SELECTOR_NACOS_ADDRESS));

Review Comment:
   Most production environments will enable authentication, so creating a NamingService requires adding username and password



##########
eventmesh-common/src/main/java/org/apache/eventmesh/common/utils/PropertiesUtils.java:
##########
@@ -61,4 +62,14 @@ public static Properties getPropertiesByPrefix(final Properties from, final Prop
         );
         return to;
     }
+
+    public static Properties readPropertiesFile(String fileName) {
+        try (final InputStream inputStream = PropertiesUtils.class.getClassLoader().getResourceAsStream(fileName)) {
+            Properties properties = new Properties();
+            properties.load(inputStream);
+            return properties;
+        } catch (Exception e) {
+            throw new IllegalArgumentException(String.format("File: %s is not exist", fileName));

Review Comment:
   Is it inappropriate to throw an IllegalArgumentException here?



-- 
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: dev-unsubscribe@eventmesh.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org