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/05/31 08:38:13 UTC

[GitHub] [incubator-eventmesh] huyuanxin opened a new pull request, #901: add consul registry implement

huyuanxin opened a new pull request, #901:
URL: https://github.com/apache/incubator-eventmesh/pull/901

   <!--
   ### Contribution Checklist
   
     - Name the pull request in the form "[ISSUE #XXXX] Title of the pull request", 
       where *XXXX* should be replaced by the actual issue number.
       Skip *[ISSUE #XXXX]* if there is no associated github issue for this pull request.
   
     - Fill out the template below to describe the changes contributed by the pull request. 
       That will give reviewers the context they need to do the review.
     
     - Each pull request should address only one issue. 
       Please do not mix up code from multiple issues.
     
     - Each commit in the pull request should have a meaningful commit message.
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, 
       leaving only the filled out template below.
   
   (The sections below can be removed for hotfixes of typos)
   -->
   
   <!--
   (If this PR fixes a GitHub issue, please add `Fixes ISSUE #<XXX>`.)
   -->
   
   Fixes ISSUE #900
   
   ### Motivation
   
   make an implement of RegistryService which is support by consul
   
   ### Modifications
   
   *Describe the modifications you've done.*
   
   Add ConsulRegistryService and ConsulConstant for implement
   Add ConsulRegistryServiceTest for test
   
   ### Documentation
   
   - Does this pull request introduce a new feature? (yes / no)
   - If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
   - If a feature is not applicable for documentation, explain why?
   - If a feature is not documented yet in this PR, please create a followup issue for adding the documentation
   


-- 
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


[GitHub] [incubator-eventmesh] xwm1992 commented on pull request #901: [ISSUE #900] Support Consul Service Registry

Posted by GitBox <gi...@apache.org>.
xwm1992 commented on PR #901:
URL: https://github.com/apache/incubator-eventmesh/pull/901#issuecomment-1197718759

   I have created the `registry-consul` branch please merge this pr to this branch and we will fix the ci problems later. @huyuanxin 


-- 
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


[GitHub] [incubator-eventmesh] xwm1992 commented on pull request #901: Support Consul Service Registry

Posted by GitBox <gi...@apache.org>.
xwm1992 commented on PR #901:
URL: https://github.com/apache/incubator-eventmesh/pull/901#issuecomment-1171019478

   please solve the conflic files @huyuanxin .


-- 
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


[GitHub] [incubator-eventmesh] huyuanxin commented on pull request #901: Support Consul Service Registry

Posted by GitBox <gi...@apache.org>.
huyuanxin commented on PR #901:
URL: https://github.com/apache/incubator-eventmesh/pull/901#issuecomment-1153804159

   
               ok, I will fix it later---- Replied Message ----FromEason ***@***.***>Date06/13/2022 19:28 ***@***.***> CcYuanXin ***@***.******@***.***>SubjectRe: [apache/incubator-eventmesh] Support Consul Service Registry (PR #901)
   @huyuanxin, please fix the issues that reqeust by @li-xiao-shuang
   
   —Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
   [
   {
   ***@***.***": "http://schema.org",
   ***@***.***": "EmailMessage",
   "potentialAction": {
   ***@***.***": "ViewAction",
   "target": "https://github.com/apache/incubator-eventmesh/pull/901#issuecomment-1153800207",
   "url": "https://github.com/apache/incubator-eventmesh/pull/901#issuecomment-1153800207",
   "name": "View Pull Request"
   },
   "description": "View this Pull Request on GitHub",
   "publisher": {
   ***@***.***": "Organization",
   "name": "GitHub",
   "url": "https://github.com"
   }
   }
   ]


-- 
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


[GitHub] [incubator-eventmesh] qqeasonchen commented on pull request #901: Support Consul Service Registry

Posted by GitBox <gi...@apache.org>.
qqeasonchen commented on PR #901:
URL: https://github.com/apache/incubator-eventmesh/pull/901#issuecomment-1152108458

   @li-xiao-shuang please help to review.


-- 
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


[GitHub] [incubator-eventmesh] huyuanxin commented on a diff in pull request #901: Support Consul Service Registry

Posted by GitBox <gi...@apache.org>.
huyuanxin commented on code in PR #901:
URL: https://github.com/apache/incubator-eventmesh/pull/901#discussion_r898646381


##########
eventmesh-registry-plugin/eventmesh-registry-consul/src/main/java/org/apache/eventmesh/registry/consul/service/ConsulRegistryService.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.registry.consul.service;
+
+import static org.apache.eventmesh.registry.consul.constant.ConsulConstant.DEFAULT_CONNECTION_TIMEOUT;
+import static org.apache.eventmesh.registry.consul.constant.ConsulConstant.DEFAULT_MAX_CONNECTIONS;
+import static org.apache.eventmesh.registry.consul.constant.ConsulConstant.DEFAULT_MAX_PER_ROUTE_CONNECTIONS;
+import static org.apache.eventmesh.registry.consul.constant.ConsulConstant.DEFAULT_READ_TIMEOUT;
+import static org.apache.eventmesh.registry.consul.constant.ConsulConstant.IP_PORT_SEPARATOR;
+
+import org.apache.eventmesh.api.exception.RegistryException;
+import org.apache.eventmesh.api.registry.RegistryService;
+import org.apache.eventmesh.api.registry.dto.EventMeshDataInfo;
+import org.apache.eventmesh.api.registry.dto.EventMeshRegisterInfo;
+import org.apache.eventmesh.api.registry.dto.EventMeshUnRegisterInfo;
+import org.apache.eventmesh.common.config.CommonConfiguration;
+import org.apache.eventmesh.common.utils.ConfigurationContextUtil;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.ecwid.consul.v1.ConsulClient;
+import com.ecwid.consul.v1.ConsulRawClient;
+import com.ecwid.consul.v1.agent.model.NewService;
+import com.ecwid.consul.v1.agent.model.Service;
+import com.ecwid.consul.v1.health.HealthServicesRequest;
+
+public class ConsulRegistryService implements RegistryService {
+
+    private static final Logger logger = LoggerFactory.getLogger(ConsulRegistryService.class);
+
+    private static final AtomicBoolean INIT_STATUS = new AtomicBoolean(false);
+
+    private static final AtomicBoolean START_STATUS = new AtomicBoolean(false);
+
+    private String consulHost;
+
+    private String consulPort;
+
+    private ConsulClient consulClient;
+
+    @Override
+    public void init() throws RegistryException {
+        if (INIT_STATUS.compareAndSet(false, true)) {
+            for (String key : ConfigurationContextUtil.KEYS) {
+                CommonConfiguration commonConfiguration = ConfigurationContextUtil.get(key);
+                if (null != commonConfiguration) {
+                    String namesrvAddr = commonConfiguration.namesrvAddr;
+                    if (StringUtils.isBlank(namesrvAddr)) {
+                        throw new RegistryException("namesrvAddr cannot be null");
+                    }
+                    String[] addr = namesrvAddr.split(":");
+                    if (addr.length != 2) {
+                        throw new RegistryException("Illegal namesrvAddr");
+                    }
+                    this.consulHost = addr[0];
+                    this.consulPort = addr[1];
+                    break;
+                }
+            }
+        }
+    }
+
+    @Override
+    public void start() throws RegistryException {
+        consulClient = new ConsulClient(new ConsulRawClient(consulHost, Integer.parseInt(consulPort), getHttpClient()));
+    }
+
+    @Override
+    public void shutdown() throws RegistryException {
+        INIT_STATUS.compareAndSet(true, false);
+        START_STATUS.compareAndSet(true, false);
+        consulClient = null;
+    }
+
+    @Override
+    public boolean register(EventMeshRegisterInfo eventMeshRegisterInfo) throws RegistryException {
+        try {
+            String[] ipPort = eventMeshRegisterInfo.getEndPoint().split(IP_PORT_SEPARATOR);
+            NewService service = new NewService();
+            service.setPort(Integer.parseInt(ipPort[1]));
+            service.setAddress(ipPort[0]);
+            service.setName(eventMeshRegisterInfo.getEventMeshClusterName());
+            service.setId(eventMeshRegisterInfo.getEventMeshClusterName() + "-" + eventMeshRegisterInfo.getEventMeshName());
+            consulClient.agentServiceRegister(service);
+        } catch (Exception e) {
+            throw new RegistryException(e.getMessage());
+        }
+        logger.info("EventMesh successfully registered to consul");
+        return true;
+    }
+
+    @Override
+    public boolean unRegister(EventMeshUnRegisterInfo eventMeshUnRegisterInfo) throws RegistryException {
+        try {
+            consulClient.agentServiceDeregister(eventMeshUnRegisterInfo.getEventMeshClusterName() + "-" + eventMeshUnRegisterInfo.getEventMeshName());
+        } catch (Exception e) {
+            throw new RegistryException(e.getMessage());
+        }
+        logger.info("EventMesh successfully unregistered to consul");
+        return true;
+    }
+
+    @Override
+    public List<EventMeshDataInfo> findEventMeshInfoByCluster(String clusterName) throws RegistryException {
+        Map<String, Service> agentServices = consulClient.getAgentServices().getValue();
+        HealthServicesRequest request = HealthServicesRequest.newBuilder().setPassing(true).build();
+        consulClient.getHealthServices(clusterName, request);
+        List<EventMeshDataInfo> eventMeshDataInfos = new ArrayList<>();
+        agentServices.forEach((k, v) -> {
+            String[] split = v.getId().split("-");
+            eventMeshDataInfos.add(new EventMeshDataInfo(split[0], split[1], v.getAddress() + ":" + v.getPort(), 0));
+        });
+        return eventMeshDataInfos;
+    }
+
+    @Override
+    public Map<String, Map<String, Integer>> findEventMeshClientDistributionData(String clusterName, String group, String purpose)
+        throws RegistryException {
+        return Collections.emptyMap();
+    }
+
+
+    private HttpClient getHttpClient() {

Review Comment:
   yep,I will delete it



-- 
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


[GitHub] [incubator-eventmesh] codecov[bot] commented on pull request #901: add consul registry implement

Posted by GitBox <gi...@apache.org>.
codecov[bot] commented on PR #901:
URL: https://github.com/apache/incubator-eventmesh/pull/901#issuecomment-1141888299

   # [Codecov](https://codecov.io/gh/apache/incubator-eventmesh/pull/901?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#901](https://codecov.io/gh/apache/incubator-eventmesh/pull/901?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (83702ad) into [master](https://codecov.io/gh/apache/incubator-eventmesh/commit/4746d73da9b4fa7eaf20f1232b023c41b39434af?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (4746d73) will **decrease** coverage by `0.06%`.
   > The diff coverage is `n/a`.
   
   > :exclamation: Current head 83702ad differs from pull request most recent head 7525c1c. Consider uploading reports for the commit 7525c1c to get more accurate results
   
   ```diff
   @@             Coverage Diff             @@
   ##             master    #901      +/-   ##
   ===========================================
   - Coverage      7.13%   7.06%   -0.07%     
   + Complexity      446     441       -5     
   ===========================================
     Files           346     346              
     Lines         21695   21682      -13     
     Branches       2415    2413       -2     
   ===========================================
   - Hits           1548    1532      -16     
   - Misses        20029   20032       +3     
     Partials        118     118              
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/incubator-eventmesh/pull/901?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...tandalone/broker/task/HistoryMessageClearTask.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/901/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLWNvbm5lY3Rvci1wbHVnaW4vZXZlbnRtZXNoLWNvbm5lY3Rvci1zdGFuZGFsb25lL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9ldmVudG1lc2gvY29ubmVjdG9yL3N0YW5kYWxvbmUvYnJva2VyL3Rhc2svSGlzdG9yeU1lc3NhZ2VDbGVhclRhc2suamF2YQ==) | `29.41% <0.00%> (-17.65%)` | :arrow_down: |
   | [...mesh/connector/standalone/broker/MessageQueue.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/901/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLWNvbm5lY3Rvci1wbHVnaW4vZXZlbnRtZXNoLWNvbm5lY3Rvci1zdGFuZGFsb25lL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9ldmVudG1lc2gvY29ubmVjdG9yL3N0YW5kYWxvbmUvYnJva2VyL01lc3NhZ2VRdWV1ZS5qYXZh) | `32.46% <0.00%> (-7.80%)` | :arrow_down: |
   | [...ava/org/apache/eventmesh/common/utils/IPUtils.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/901/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLWNvbW1vbi9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZXZlbnRtZXNoL2NvbW1vbi91dGlscy9JUFV0aWxzLmphdmE=) | `33.33% <0.00%> (-6.49%)` | :arrow_down: |
   | [...che/eventmesh/runtime/boot/AbstractHTTPServer.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/901/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLXJ1bnRpbWUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9ydW50aW1lL2Jvb3QvQWJzdHJhY3RIVFRQU2VydmVyLmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...che/eventmesh/runtime/boot/EventMeshTCPServer.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/901/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLXJ1bnRpbWUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9ydW50aW1lL2Jvb3QvRXZlbnRNZXNoVENQU2VydmVyLmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...sh/client/http/producer/EventMeshHttpProducer.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/901/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLXNkay1qYXZhL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9ldmVudG1lc2gvY2xpZW50L2h0dHAvcHJvZHVjZXIvRXZlbnRNZXNoSHR0cFByb2R1Y2VyLmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...core/protocol/http/consumer/EventMeshConsumer.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/901/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLXJ1bnRpbWUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9ydW50aW1lL2NvcmUvcHJvdG9jb2wvaHR0cC9jb25zdW1lci9FdmVudE1lc2hDb25zdW1lci5qYXZh) | `0.00% <0.00%> (ø)` | |
   | [.../protocol/tcp/client/group/ClientGroupWrapper.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/901/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLXJ1bnRpbWUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9ydW50aW1lL2NvcmUvcHJvdG9jb2wvdGNwL2NsaWVudC9ncm91cC9DbGllbnRHcm91cFdyYXBwZXIuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...ol/tcp/client/session/send/UpStreamMsgContext.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/901/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLXJ1bnRpbWUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9ydW50aW1lL2NvcmUvcHJvdG9jb2wvdGNwL2NsaWVudC9zZXNzaW9uL3NlbmQvVXBTdHJlYW1Nc2dDb250ZXh0LmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...pl/consumer/ConsumeMessageConcurrentlyService.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/901/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLWNvbm5lY3Rvci1wbHVnaW4vZXZlbnRtZXNoLWNvbm5lY3Rvci1yb2NrZXRtcS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcm9ja2V0bXEvY2xpZW50L2ltcGwvY29uc3VtZXIvQ29uc3VtZU1lc3NhZ2VDb25jdXJyZW50bHlTZXJ2aWNlLmphdmE=) | `0.00% <0.00%> (ø)` | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/incubator-eventmesh/pull/901?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/incubator-eventmesh/pull/901?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [4746d73...7525c1c](https://codecov.io/gh/apache/incubator-eventmesh/pull/901?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
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


[GitHub] [incubator-eventmesh] li-xiao-shuang commented on pull request #901: Support Consul Service Registry

Posted by GitBox <gi...@apache.org>.
li-xiao-shuang commented on PR #901:
URL: https://github.com/apache/incubator-eventmesh/pull/901#issuecomment-1153112704

   How does the heartbeat of the consul service work? Need manual maintenance?


-- 
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


[GitHub] [incubator-eventmesh] li-xiao-shuang commented on a diff in pull request #901: Support Consul Service Registry

Posted by GitBox <gi...@apache.org>.
li-xiao-shuang commented on code in PR #901:
URL: https://github.com/apache/incubator-eventmesh/pull/901#discussion_r898647020


##########
eventmesh-registry-plugin/eventmesh-registry-consul/src/main/java/org/apache/eventmesh/registry/consul/service/ConsulRegistryService.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.registry.consul.service;
+
+import static org.apache.eventmesh.registry.consul.constant.ConsulConstant.DEFAULT_CONNECTION_TIMEOUT;
+import static org.apache.eventmesh.registry.consul.constant.ConsulConstant.DEFAULT_MAX_CONNECTIONS;
+import static org.apache.eventmesh.registry.consul.constant.ConsulConstant.DEFAULT_MAX_PER_ROUTE_CONNECTIONS;
+import static org.apache.eventmesh.registry.consul.constant.ConsulConstant.DEFAULT_READ_TIMEOUT;
+import static org.apache.eventmesh.registry.consul.constant.ConsulConstant.IP_PORT_SEPARATOR;
+
+import org.apache.eventmesh.api.exception.RegistryException;
+import org.apache.eventmesh.api.registry.RegistryService;
+import org.apache.eventmesh.api.registry.dto.EventMeshDataInfo;
+import org.apache.eventmesh.api.registry.dto.EventMeshRegisterInfo;
+import org.apache.eventmesh.api.registry.dto.EventMeshUnRegisterInfo;
+import org.apache.eventmesh.common.config.CommonConfiguration;
+import org.apache.eventmesh.common.utils.ConfigurationContextUtil;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.ecwid.consul.v1.ConsulClient;
+import com.ecwid.consul.v1.ConsulRawClient;
+import com.ecwid.consul.v1.agent.model.NewService;
+import com.ecwid.consul.v1.agent.model.Service;
+import com.ecwid.consul.v1.health.HealthServicesRequest;
+
+public class ConsulRegistryService implements RegistryService {
+
+    private static final Logger logger = LoggerFactory.getLogger(ConsulRegistryService.class);
+
+    private static final AtomicBoolean INIT_STATUS = new AtomicBoolean(false);
+
+    private static final AtomicBoolean START_STATUS = new AtomicBoolean(false);
+
+    private String consulHost;
+
+    private String consulPort;
+
+    private ConsulClient consulClient;
+
+    @Override
+    public void init() throws RegistryException {
+        if (INIT_STATUS.compareAndSet(false, true)) {
+            for (String key : ConfigurationContextUtil.KEYS) {
+                CommonConfiguration commonConfiguration = ConfigurationContextUtil.get(key);
+                if (null != commonConfiguration) {
+                    String namesrvAddr = commonConfiguration.namesrvAddr;
+                    if (StringUtils.isBlank(namesrvAddr)) {
+                        throw new RegistryException("namesrvAddr cannot be null");
+                    }
+                    String[] addr = namesrvAddr.split(":");
+                    if (addr.length != 2) {
+                        throw new RegistryException("Illegal namesrvAddr");
+                    }
+                    this.consulHost = addr[0];
+                    this.consulPort = addr[1];
+                    break;
+                }
+            }
+        }
+    }
+
+    @Override
+    public void start() throws RegistryException {
+        consulClient = new ConsulClient(new ConsulRawClient(consulHost, Integer.parseInt(consulPort), getHttpClient()));

Review Comment:
   > Token support?
   
   Yes, authentication needs to be turned on in actual applications, so it needs to support authentication



-- 
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


[GitHub] [incubator-eventmesh] huyuanxin commented on pull request #901: add consul registry implement

Posted by GitBox <gi...@apache.org>.
huyuanxin commented on PR #901:
URL: https://github.com/apache/incubator-eventmesh/pull/901#issuecomment-1141939812

   It seems that MacOS 11 build scrip is failed, because could not get resource


-- 
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


[GitHub] [incubator-eventmesh] xwm1992 merged pull request #901: [ISSUE #900] Support Consul Service Registry

Posted by GitBox <gi...@apache.org>.
xwm1992 merged PR #901:
URL: https://github.com/apache/incubator-eventmesh/pull/901


-- 
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


[GitHub] [incubator-eventmesh] xiaoyang-sde commented on pull request #901: add consul registry implement

Posted by GitBox <gi...@apache.org>.
xiaoyang-sde commented on PR #901:
URL: https://github.com/apache/incubator-eventmesh/pull/901#issuecomment-1143059795

   > @xiaoyang-sde please help to review
   
   Sure! I will review it later today.


-- 
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


[GitHub] [incubator-eventmesh] huyuanxin commented on pull request #901: Support Consul Service Registry

Posted by GitBox <gi...@apache.org>.
huyuanxin commented on PR #901:
URL: https://github.com/apache/incubator-eventmesh/pull/901#issuecomment-1144329807

   > 
   
   yep. I will fix it later or tomorrow, work is busy


-- 
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


[GitHub] [incubator-eventmesh] li-xiao-shuang commented on a diff in pull request #901: Support Consul Service Registry

Posted by GitBox <gi...@apache.org>.
li-xiao-shuang commented on code in PR #901:
URL: https://github.com/apache/incubator-eventmesh/pull/901#discussion_r895138755


##########
eventmesh-registry-plugin/eventmesh-registry-consul/src/main/java/org/apache/eventmesh/registry/consul/service/ConsulRegistryService.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.registry.consul.service;
+
+import static org.apache.eventmesh.registry.consul.constant.ConsulConstant.DEFAULT_CONNECTION_TIMEOUT;
+import static org.apache.eventmesh.registry.consul.constant.ConsulConstant.DEFAULT_MAX_CONNECTIONS;
+import static org.apache.eventmesh.registry.consul.constant.ConsulConstant.DEFAULT_MAX_PER_ROUTE_CONNECTIONS;
+import static org.apache.eventmesh.registry.consul.constant.ConsulConstant.DEFAULT_READ_TIMEOUT;
+import static org.apache.eventmesh.registry.consul.constant.ConsulConstant.IP_PORT_SEPARATOR;
+
+import org.apache.eventmesh.api.exception.RegistryException;
+import org.apache.eventmesh.api.registry.RegistryService;
+import org.apache.eventmesh.api.registry.dto.EventMeshDataInfo;
+import org.apache.eventmesh.api.registry.dto.EventMeshRegisterInfo;
+import org.apache.eventmesh.api.registry.dto.EventMeshUnRegisterInfo;
+import org.apache.eventmesh.common.config.CommonConfiguration;
+import org.apache.eventmesh.common.utils.ConfigurationContextUtil;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.ecwid.consul.v1.ConsulClient;
+import com.ecwid.consul.v1.ConsulRawClient;
+import com.ecwid.consul.v1.agent.model.NewService;
+import com.ecwid.consul.v1.agent.model.Service;
+import com.ecwid.consul.v1.health.HealthServicesRequest;
+
+public class ConsulRegistryService implements RegistryService {
+
+    private static final Logger logger = LoggerFactory.getLogger(ConsulRegistryService.class);
+
+    private static final AtomicBoolean INIT_STATUS = new AtomicBoolean(false);
+
+    private static final AtomicBoolean START_STATUS = new AtomicBoolean(false);
+
+    private String consulHost;
+
+    private String consulPort;
+
+    private ConsulClient consulClient;
+
+    @Override
+    public void init() throws RegistryException {
+        if (INIT_STATUS.compareAndSet(false, true)) {
+            for (String key : ConfigurationContextUtil.KEYS) {
+                CommonConfiguration commonConfiguration = ConfigurationContextUtil.get(key);
+                if (null != commonConfiguration) {
+                    String namesrvAddr = commonConfiguration.namesrvAddr;
+                    if (StringUtils.isBlank(namesrvAddr)) {
+                        throw new RegistryException("namesrvAddr cannot be null");
+                    }
+                    String[] addr = namesrvAddr.split(":");
+                    if (addr.length != 2) {
+                        throw new RegistryException("Illegal namesrvAddr");
+                    }
+                    this.consulHost = addr[0];
+                    this.consulPort = addr[1];
+                    break;
+                }
+            }
+        }
+    }
+
+    @Override
+    public void start() throws RegistryException {
+        consulClient = new ConsulClient(new ConsulRawClient(consulHost, Integer.parseInt(consulPort), getHttpClient()));
+    }
+
+    @Override
+    public void shutdown() throws RegistryException {
+        INIT_STATUS.compareAndSet(true, false);
+        START_STATUS.compareAndSet(true, false);
+        consulClient = null;
+    }
+
+    @Override
+    public boolean register(EventMeshRegisterInfo eventMeshRegisterInfo) throws RegistryException {
+        try {
+            String[] ipPort = eventMeshRegisterInfo.getEndPoint().split(IP_PORT_SEPARATOR);
+            NewService service = new NewService();
+            service.setPort(Integer.parseInt(ipPort[1]));
+            service.setAddress(ipPort[0]);
+            service.setName(eventMeshRegisterInfo.getEventMeshClusterName());

Review Comment:
   Many service instances may share the same logical service name. The service name of eventmesh should be used here, not the cluster name. Can the namespace of consul distinguish clusters?



-- 
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


[GitHub] [incubator-eventmesh] li-xiao-shuang commented on pull request #901: Support Consul Service Registry

Posted by GitBox <gi...@apache.org>.
li-xiao-shuang commented on PR #901:
URL: https://github.com/apache/incubator-eventmesh/pull/901#issuecomment-1153085499

   > @li-xiao-shuang please help to review.
   
   Yes, I'm working on it


-- 
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


[GitHub] [incubator-eventmesh] qqeasonchen commented on pull request #901: Support Consul Service Registry

Posted by GitBox <gi...@apache.org>.
qqeasonchen commented on PR #901:
URL: https://github.com/apache/incubator-eventmesh/pull/901#issuecomment-1152107277

   @huyuanxin any udpates?


-- 
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


[GitHub] [incubator-eventmesh] huyuanxin commented on pull request #901: [ISSUE #900] Support Consul Service Registry

Posted by GitBox <gi...@apache.org>.
huyuanxin commented on PR #901:
URL: https://github.com/apache/incubator-eventmesh/pull/901#issuecomment-1188511720

   > @huyuanxin can you please fix the conflicts?
   
   fixing


-- 
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


[GitHub] [incubator-eventmesh] huyuanxin commented on pull request #901: add consul registry implement

Posted by GitBox <gi...@apache.org>.
huyuanxin commented on PR #901:
URL: https://github.com/apache/incubator-eventmesh/pull/901#issuecomment-1142841086

   > seems miss lisence declare
   
   FAILURE: Build failed with an exception.
   38 actionable tasks: 5 executed, 33 up-to-date
   
   * What went wrong:
   Execution failed for task ':eventmesh-common:compileJava'.
   > Could not resolve all files for configuration ':eventmesh-common:compileClasspath'.
      > Could not download log4j-core-2.17.1.jar (org.apache.logging.log4j:log4j-core:2.17.1)
         > Could not get resource 'https://maven.aliyun.com/repository/public/org/apache/logging/log4j/log4j-core/2.17.1/log4j-core-2.17.1.jar'.
            > Premature end of Content-Length delimited message body (expected: 1,790,452; received: 70,916)
   
   * Try:
   > Run with --stacktrace option to get the stack trace.
   > Run with --info or --debug option to get more log output.
   > Run with --scan to get full insights.
   
   * Get more help at https://help.gradle.org/
   
   BUILD FAILED in 2m 10s
   
   it seems there is something wrong with gradle build


-- 
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


[GitHub] [incubator-eventmesh] qqeasonchen commented on pull request #901: add consul registry implement

Posted by GitBox <gi...@apache.org>.
qqeasonchen commented on PR #901:
URL: https://github.com/apache/incubator-eventmesh/pull/901#issuecomment-1143048028

   @xiaoyang-sde please help to review


-- 
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


[GitHub] [incubator-eventmesh] huyuanxin commented on pull request #901: Support Consul Service Registry

Posted by GitBox <gi...@apache.org>.
huyuanxin commented on PR #901:
URL: https://github.com/apache/incubator-eventmesh/pull/901#issuecomment-1152148066

   already done, but some check still can't be resolved. I can't figure it out
   
   在 2022年6月10日,16:24,Eason Chen ***@***.***> 写道:
   
   
   
   @huyuanxin<https://github.com/huyuanxin> any udpates?
   
   —
   Reply to this email directly, view it on GitHub<https://github.com/apache/incubator-eventmesh/pull/901#issuecomment-1152107277>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AKC764POFM5KLP3ZKE3DAM3VOL3SNANCNFSM5XMX3GHA>.
   You are receiving this because you were mentioned.Message ID: ***@***.***>
   


-- 
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


[GitHub] [incubator-eventmesh] li-xiao-shuang commented on a diff in pull request #901: Support Consul Service Registry

Posted by GitBox <gi...@apache.org>.
li-xiao-shuang commented on code in PR #901:
URL: https://github.com/apache/incubator-eventmesh/pull/901#discussion_r895133251


##########
eventmesh-registry-plugin/eventmesh-registry-consul/src/main/java/org/apache/eventmesh/registry/consul/service/ConsulRegistryService.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.registry.consul.service;
+
+import static org.apache.eventmesh.registry.consul.constant.ConsulConstant.DEFAULT_CONNECTION_TIMEOUT;
+import static org.apache.eventmesh.registry.consul.constant.ConsulConstant.DEFAULT_MAX_CONNECTIONS;
+import static org.apache.eventmesh.registry.consul.constant.ConsulConstant.DEFAULT_MAX_PER_ROUTE_CONNECTIONS;
+import static org.apache.eventmesh.registry.consul.constant.ConsulConstant.DEFAULT_READ_TIMEOUT;
+import static org.apache.eventmesh.registry.consul.constant.ConsulConstant.IP_PORT_SEPARATOR;
+
+import org.apache.eventmesh.api.exception.RegistryException;
+import org.apache.eventmesh.api.registry.RegistryService;
+import org.apache.eventmesh.api.registry.dto.EventMeshDataInfo;
+import org.apache.eventmesh.api.registry.dto.EventMeshRegisterInfo;
+import org.apache.eventmesh.api.registry.dto.EventMeshUnRegisterInfo;
+import org.apache.eventmesh.common.config.CommonConfiguration;
+import org.apache.eventmesh.common.utils.ConfigurationContextUtil;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.ecwid.consul.v1.ConsulClient;
+import com.ecwid.consul.v1.ConsulRawClient;
+import com.ecwid.consul.v1.agent.model.NewService;
+import com.ecwid.consul.v1.agent.model.Service;
+import com.ecwid.consul.v1.health.HealthServicesRequest;
+
+public class ConsulRegistryService implements RegistryService {
+
+    private static final Logger logger = LoggerFactory.getLogger(ConsulRegistryService.class);
+
+    private static final AtomicBoolean INIT_STATUS = new AtomicBoolean(false);
+
+    private static final AtomicBoolean START_STATUS = new AtomicBoolean(false);
+
+    private String consulHost;
+
+    private String consulPort;
+
+    private ConsulClient consulClient;
+
+    @Override
+    public void init() throws RegistryException {
+        if (INIT_STATUS.compareAndSet(false, true)) {
+            for (String key : ConfigurationContextUtil.KEYS) {
+                CommonConfiguration commonConfiguration = ConfigurationContextUtil.get(key);
+                if (null != commonConfiguration) {
+                    String namesrvAddr = commonConfiguration.namesrvAddr;
+                    if (StringUtils.isBlank(namesrvAddr)) {
+                        throw new RegistryException("namesrvAddr cannot be null");
+                    }
+                    String[] addr = namesrvAddr.split(":");
+                    if (addr.length != 2) {
+                        throw new RegistryException("Illegal namesrvAddr");
+                    }
+                    this.consulHost = addr[0];
+                    this.consulPort = addr[1];
+                    break;
+                }
+            }
+        }
+    }
+
+    @Override
+    public void start() throws RegistryException {
+        consulClient = new ConsulClient(new ConsulRawClient(consulHost, Integer.parseInt(consulPort), getHttpClient()));

Review Comment:
   I think ACL should be supported



-- 
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


[GitHub] [incubator-eventmesh] huyuanxin commented on pull request #901: [ISSUE #900] Support Consul Service Registry

Posted by GitBox <gi...@apache.org>.
huyuanxin commented on PR #901:
URL: https://github.com/apache/incubator-eventmesh/pull/901#issuecomment-1188529271

   I cherry pick from latest upstream


-- 
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


[GitHub] [incubator-eventmesh] qqeasonchen commented on pull request #901: [ISSUE #900] Support Consul Service Registry

Posted by GitBox <gi...@apache.org>.
qqeasonchen commented on PR #901:
URL: https://github.com/apache/incubator-eventmesh/pull/901#issuecomment-1188506299

   @huyuanxin can you please fix the conflicts?


-- 
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


[GitHub] [incubator-eventmesh] huyuanxin commented on pull request #901: Support Consul Service Registry

Posted by GitBox <gi...@apache.org>.
huyuanxin commented on PR #901:
URL: https://github.com/apache/incubator-eventmesh/pull/901#issuecomment-1152149005

   Already done. But I can't figure out how to fix the action checks
   
   在 2022年6月10日,16:24,Eason Chen ***@***.***> 写道:
   
   
   
   @huyuanxin<https://github.com/huyuanxin> any udpates?
   
   —
   Reply to this email directly, view it on GitHub<https://github.com/apache/incubator-eventmesh/pull/901#issuecomment-1152107277>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AKC764POFM5KLP3ZKE3DAM3VOL3SNANCNFSM5XMX3GHA>.
   You are receiving this because you were mentioned.Message ID: ***@***.***>
   


-- 
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


[GitHub] [incubator-eventmesh] qqeasonchen commented on pull request #901: Support Consul Service Registry

Posted by GitBox <gi...@apache.org>.
qqeasonchen commented on PR #901:
URL: https://github.com/apache/incubator-eventmesh/pull/901#issuecomment-1153800207

   @huyuanxin, please fix the issues that reqeust by @li-xiao-shuang 


-- 
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


[GitHub] [incubator-eventmesh] li-xiao-shuang commented on a diff in pull request #901: Support Consul Service Registry

Posted by GitBox <gi...@apache.org>.
li-xiao-shuang commented on code in PR #901:
URL: https://github.com/apache/incubator-eventmesh/pull/901#discussion_r895134164


##########
eventmesh-registry-plugin/eventmesh-registry-consul/src/main/java/org/apache/eventmesh/registry/consul/service/ConsulRegistryService.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.registry.consul.service;
+
+import static org.apache.eventmesh.registry.consul.constant.ConsulConstant.DEFAULT_CONNECTION_TIMEOUT;
+import static org.apache.eventmesh.registry.consul.constant.ConsulConstant.DEFAULT_MAX_CONNECTIONS;
+import static org.apache.eventmesh.registry.consul.constant.ConsulConstant.DEFAULT_MAX_PER_ROUTE_CONNECTIONS;
+import static org.apache.eventmesh.registry.consul.constant.ConsulConstant.DEFAULT_READ_TIMEOUT;
+import static org.apache.eventmesh.registry.consul.constant.ConsulConstant.IP_PORT_SEPARATOR;
+
+import org.apache.eventmesh.api.exception.RegistryException;
+import org.apache.eventmesh.api.registry.RegistryService;
+import org.apache.eventmesh.api.registry.dto.EventMeshDataInfo;
+import org.apache.eventmesh.api.registry.dto.EventMeshRegisterInfo;
+import org.apache.eventmesh.api.registry.dto.EventMeshUnRegisterInfo;
+import org.apache.eventmesh.common.config.CommonConfiguration;
+import org.apache.eventmesh.common.utils.ConfigurationContextUtil;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.ecwid.consul.v1.ConsulClient;
+import com.ecwid.consul.v1.ConsulRawClient;
+import com.ecwid.consul.v1.agent.model.NewService;
+import com.ecwid.consul.v1.agent.model.Service;
+import com.ecwid.consul.v1.health.HealthServicesRequest;
+
+public class ConsulRegistryService implements RegistryService {
+
+    private static final Logger logger = LoggerFactory.getLogger(ConsulRegistryService.class);
+
+    private static final AtomicBoolean INIT_STATUS = new AtomicBoolean(false);
+
+    private static final AtomicBoolean START_STATUS = new AtomicBoolean(false);
+
+    private String consulHost;
+
+    private String consulPort;
+
+    private ConsulClient consulClient;
+
+    @Override
+    public void init() throws RegistryException {
+        if (INIT_STATUS.compareAndSet(false, true)) {
+            for (String key : ConfigurationContextUtil.KEYS) {
+                CommonConfiguration commonConfiguration = ConfigurationContextUtil.get(key);
+                if (null != commonConfiguration) {
+                    String namesrvAddr = commonConfiguration.namesrvAddr;
+                    if (StringUtils.isBlank(namesrvAddr)) {
+                        throw new RegistryException("namesrvAddr cannot be null");
+                    }
+                    String[] addr = namesrvAddr.split(":");
+                    if (addr.length != 2) {
+                        throw new RegistryException("Illegal namesrvAddr");
+                    }
+                    this.consulHost = addr[0];
+                    this.consulPort = addr[1];
+                    break;
+                }
+            }
+        }
+    }
+
+    @Override
+    public void start() throws RegistryException {
+        consulClient = new ConsulClient(new ConsulRawClient(consulHost, Integer.parseInt(consulPort), getHttpClient()));
+    }
+
+    @Override
+    public void shutdown() throws RegistryException {
+        INIT_STATUS.compareAndSet(true, false);
+        START_STATUS.compareAndSet(true, false);
+        consulClient = null;
+    }
+
+    @Override
+    public boolean register(EventMeshRegisterInfo eventMeshRegisterInfo) throws RegistryException {
+        try {
+            String[] ipPort = eventMeshRegisterInfo.getEndPoint().split(IP_PORT_SEPARATOR);
+            NewService service = new NewService();
+            service.setPort(Integer.parseInt(ipPort[1]));
+            service.setAddress(ipPort[0]);
+            service.setName(eventMeshRegisterInfo.getEventMeshClusterName());
+            service.setId(eventMeshRegisterInfo.getEventMeshClusterName() + "-" + eventMeshRegisterInfo.getEventMeshName());
+            consulClient.agentServiceRegister(service);
+        } catch (Exception e) {
+            throw new RegistryException(e.getMessage());
+        }
+        logger.info("EventMesh successfully registered to consul");
+        return true;
+    }
+
+    @Override
+    public boolean unRegister(EventMeshUnRegisterInfo eventMeshUnRegisterInfo) throws RegistryException {
+        try {
+            consulClient.agentServiceDeregister(eventMeshUnRegisterInfo.getEventMeshClusterName() + "-" + eventMeshUnRegisterInfo.getEventMeshName());
+        } catch (Exception e) {
+            throw new RegistryException(e.getMessage());
+        }
+        logger.info("EventMesh successfully unregistered to consul");
+        return true;
+    }
+
+    @Override
+    public List<EventMeshDataInfo> findEventMeshInfoByCluster(String clusterName) throws RegistryException {
+        Map<String, Service> agentServices = consulClient.getAgentServices().getValue();
+        HealthServicesRequest request = HealthServicesRequest.newBuilder().setPassing(true).build();
+        consulClient.getHealthServices(clusterName, request);
+        List<EventMeshDataInfo> eventMeshDataInfos = new ArrayList<>();
+        agentServices.forEach((k, v) -> {
+            String[] split = v.getId().split("-");
+            eventMeshDataInfos.add(new EventMeshDataInfo(split[0], split[1], v.getAddress() + ":" + v.getPort(), 0));
+        });
+        return eventMeshDataInfos;
+    }
+
+    @Override
+    public Map<String, Map<String, Integer>> findEventMeshClientDistributionData(String clusterName, String group, String purpose)
+        throws RegistryException {
+        return Collections.emptyMap();
+    }
+
+
+    private HttpClient getHttpClient() {

Review Comment:
   consul already provides DEFAULT_HTTP_TRANSPORT, I don't think this code is necessary



-- 
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


[GitHub] [incubator-eventmesh] li-xiao-shuang commented on pull request #901: Support Consul Service Registry

Posted by GitBox <gi...@apache.org>.
li-xiao-shuang commented on PR #901:
URL: https://github.com/apache/incubator-eventmesh/pull/901#issuecomment-1153101360

   You should create a META-INF/eventmesh/org.apache.eventmesh.api.registry.RegistryService file for the consul plugin so the eventmesh spi will find it


-- 
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


[GitHub] [incubator-eventmesh] huyuanxin commented on a diff in pull request #901: Support Consul Service Registry

Posted by GitBox <gi...@apache.org>.
huyuanxin commented on code in PR #901:
URL: https://github.com/apache/incubator-eventmesh/pull/901#discussion_r898644132


##########
eventmesh-registry-plugin/eventmesh-registry-consul/src/main/java/org/apache/eventmesh/registry/consul/service/ConsulRegistryService.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.registry.consul.service;
+
+import static org.apache.eventmesh.registry.consul.constant.ConsulConstant.DEFAULT_CONNECTION_TIMEOUT;
+import static org.apache.eventmesh.registry.consul.constant.ConsulConstant.DEFAULT_MAX_CONNECTIONS;
+import static org.apache.eventmesh.registry.consul.constant.ConsulConstant.DEFAULT_MAX_PER_ROUTE_CONNECTIONS;
+import static org.apache.eventmesh.registry.consul.constant.ConsulConstant.DEFAULT_READ_TIMEOUT;
+import static org.apache.eventmesh.registry.consul.constant.ConsulConstant.IP_PORT_SEPARATOR;
+
+import org.apache.eventmesh.api.exception.RegistryException;
+import org.apache.eventmesh.api.registry.RegistryService;
+import org.apache.eventmesh.api.registry.dto.EventMeshDataInfo;
+import org.apache.eventmesh.api.registry.dto.EventMeshRegisterInfo;
+import org.apache.eventmesh.api.registry.dto.EventMeshUnRegisterInfo;
+import org.apache.eventmesh.common.config.CommonConfiguration;
+import org.apache.eventmesh.common.utils.ConfigurationContextUtil;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.ecwid.consul.v1.ConsulClient;
+import com.ecwid.consul.v1.ConsulRawClient;
+import com.ecwid.consul.v1.agent.model.NewService;
+import com.ecwid.consul.v1.agent.model.Service;
+import com.ecwid.consul.v1.health.HealthServicesRequest;
+
+public class ConsulRegistryService implements RegistryService {
+
+    private static final Logger logger = LoggerFactory.getLogger(ConsulRegistryService.class);
+
+    private static final AtomicBoolean INIT_STATUS = new AtomicBoolean(false);
+
+    private static final AtomicBoolean START_STATUS = new AtomicBoolean(false);
+
+    private String consulHost;
+
+    private String consulPort;
+
+    private ConsulClient consulClient;
+
+    @Override
+    public void init() throws RegistryException {
+        if (INIT_STATUS.compareAndSet(false, true)) {
+            for (String key : ConfigurationContextUtil.KEYS) {
+                CommonConfiguration commonConfiguration = ConfigurationContextUtil.get(key);
+                if (null != commonConfiguration) {
+                    String namesrvAddr = commonConfiguration.namesrvAddr;
+                    if (StringUtils.isBlank(namesrvAddr)) {
+                        throw new RegistryException("namesrvAddr cannot be null");
+                    }
+                    String[] addr = namesrvAddr.split(":");
+                    if (addr.length != 2) {
+                        throw new RegistryException("Illegal namesrvAddr");
+                    }
+                    this.consulHost = addr[0];
+                    this.consulPort = addr[1];
+                    break;
+                }
+            }
+        }
+    }
+
+    @Override
+    public void start() throws RegistryException {
+        consulClient = new ConsulClient(new ConsulRawClient(consulHost, Integer.parseInt(consulPort), getHttpClient()));

Review Comment:
   Token support?



-- 
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