Skip to content

Commit

Permalink
Support Consul register #1148 (#1174)
Browse files Browse the repository at this point in the history
* consul client

* consul server

* consul other clients

* fix test case and checking

* update config

* delete unuse variate
  • Loading branch information
MarcusJiang1306 authored Mar 18, 2021
1 parent 8d3dc60 commit 070ede2
Show file tree
Hide file tree
Showing 60 changed files with 956 additions and 164 deletions.
14 changes: 14 additions & 0 deletions soul-admin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.dromara</groupId>
<artifactId>soul-register-server-consul</artifactId>
<version>${project.version}</version>
</dependency>

<!--soul consul register start-->
<!--<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
<version>2.2.6.RELEASE</version>
</dependency>-->
<!--soul consul register end-->

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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.dromara.soul.admin.config;

import org.dromara.soul.register.common.config.SoulRegisterCenterConfig;
import org.dromara.soul.register.server.consul.SoulConsulConfigWatch;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnProperty(prefix = "soul.register", name = "registerType", havingValue = "consul")
public class ConsulServerConfiguration {

/**
* Register soulConsulConfigWatch for ConsulServerRegisterRepository to monitor metadata.
*
* @param config the soul register center config
* @param publisher the application event publisher
* @return the consul config watch
*/
@Bean
public SoulConsulConfigWatch soulConsulConfigWatch(final SoulRegisterCenterConfig config, final ApplicationEventPublisher publisher) {
return new SoulConsulConfigWatch(config, publisher);
}
}
4 changes: 2 additions & 2 deletions soul-admin/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ mybatis:

soul:
register:
registerType: http #http #zookeeper #etcd
serverLists : #localhost:2181 #http://localhost:2379
registerType: http #http #zookeeper #etcd consul
serverLists : http://localhost:9095 #localhost:2181 #http://localhost:2379
props:
sessionTimeout: 5000
connectionTimeout: 2000
Expand Down
22 changes: 22 additions & 0 deletions soul-bootstrap/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,28 @@
<version>${project.version}</version>
</dependency>

<!--soul tars plugin end-->
<!-- <dependency>-->
<!-- <groupId>org.dromara</groupId>-->
<!-- <artifactId>soul-spring-boot-starter-plugin-tars</artifactId>-->
<!-- <version>${project.version}</version>-->
<!-- </dependency>-->

<!-- <dependency>-->
<!-- <groupId>com.tencent.tars</groupId>-->
<!-- <artifactId>tars-client</artifactId>-->
<!-- <version>1.7.2</version>-->
<!-- </dependency>-->
<!--soul tars plugin end-->

<!--soul grpc plugin start-->
<!-- <dependency>-->
<!-- <groupId>org.dromara</groupId>-->
<!-- <artifactId>soul-spring-boot-starter-plugin-grpc</artifactId>-->
<!-- <version>${project.version}</version>-->
<!-- </dependency>-->
<!--soul grpc plugin end-->

<!--if you use http proxy end this-->

<!--soul sofa plugin start-->
Expand Down
5 changes: 5 additions & 0 deletions soul-client/soul-client-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,10 @@
<artifactId>soul-register-client-etcd</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.dromara</groupId>
<artifactId>soul-register-client-consul</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.alibaba.dubbo.config.spring.ServiceBean;
import lombok.extern.slf4j.Slf4j;
import org.dromara.soul.client.core.disruptor.SoulClientRegisterEventPublisher;
import org.dromara.soul.client.core.register.SoulClientRegisterRepositoryFactory;
import org.dromara.soul.client.dubbo.common.annotation.SoulDubboClient;
import org.dromara.soul.client.dubbo.common.dto.DubboRpcExt;
import org.dromara.soul.common.utils.GsonUtils;
Expand Down Expand Up @@ -65,7 +64,7 @@ public class AlibabaDubboServiceBeanPostProcessor implements ApplicationListener

private final String appName;

public AlibabaDubboServiceBeanPostProcessor(final SoulRegisterCenterConfig config) {
public AlibabaDubboServiceBeanPostProcessor(final SoulRegisterCenterConfig config, final SoulClientRegisterRepository soulClientRegisterRepository) {
Properties props = config.getProps();
String contextPath = props.getProperty("contextPath");
String appName = props.getProperty("appName");
Expand All @@ -75,7 +74,6 @@ public AlibabaDubboServiceBeanPostProcessor(final SoulRegisterCenterConfig confi
this.contextPath = contextPath;
this.appName = appName;
executorService = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
SoulClientRegisterRepository soulClientRegisterRepository = SoulClientRegisterRepositoryFactory.newInstance(config);
publisher.start(soulClientRegisterRepository);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.spring.ServiceBean;
import org.dromara.soul.client.core.disruptor.SoulClientRegisterEventPublisher;
import org.dromara.soul.client.core.register.SoulClientRegisterRepositoryFactory;
import org.dromara.soul.client.dubbo.common.annotation.SoulDubboClient;
import org.dromara.soul.client.dubbo.common.dto.DubboRpcExt;
import org.dromara.soul.common.utils.GsonUtils;
Expand Down Expand Up @@ -65,7 +64,7 @@ public class ApacheDubboServiceBeanPostProcessor implements ApplicationListener<

private String appName;

public ApacheDubboServiceBeanPostProcessor(final SoulRegisterCenterConfig config) {
public ApacheDubboServiceBeanPostProcessor(final SoulRegisterCenterConfig config, final SoulClientRegisterRepository soulClientRegisterRepository) {
Properties props = config.getProps();
String contextPath = props.getProperty("contextPath");
String appName = props.getProperty("appName");
Expand All @@ -75,7 +74,6 @@ public ApacheDubboServiceBeanPostProcessor(final SoulRegisterCenterConfig config
this.contextPath = contextPath;
this.appName = appName;
executorService = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
SoulClientRegisterRepository soulClientRegisterRepository = SoulClientRegisterRepositoryFactory.newInstance(config);
soulClientRegisterEventPublisher.start(soulClientRegisterRepository);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import io.grpc.BindableService;
import lombok.extern.slf4j.Slf4j;
import org.dromara.soul.client.core.disruptor.SoulClientRegisterEventPublisher;
import org.dromara.soul.client.core.register.SoulClientRegisterRepositoryFactory;
import org.dromara.soul.client.grpc.common.annotation.SoulGrpcClient;
import org.dromara.soul.client.grpc.common.dto.GrpcExt;
import org.dromara.soul.common.utils.GsonUtils;
Expand Down Expand Up @@ -69,8 +68,9 @@ public class GrpcClientBeanPostProcessor implements BeanPostProcessor {
* Instantiates a new Soul client bean post processor.
*
* @param config the soul grpc config
* @param soulClientRegisterRepository the soulClientRegisterRepository
*/
public GrpcClientBeanPostProcessor(final SoulRegisterCenterConfig config) {
public GrpcClientBeanPostProcessor(final SoulRegisterCenterConfig config, final SoulClientRegisterRepository soulClientRegisterRepository) {
Properties props = config.getProps();
String contextPath = props.getProperty("contextPath");
String ipAndPort = props.getProperty("ipAndPort");
Expand All @@ -83,7 +83,6 @@ public GrpcClientBeanPostProcessor(final SoulRegisterCenterConfig config) {
this.host = props.getProperty("host");
this.port = Integer.parseInt(port);
executorService = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
SoulClientRegisterRepository soulClientRegisterRepository = SoulClientRegisterRepositoryFactory.newInstance(config);
publisher.start(soulClientRegisterRepository);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@

package org.dromara.soul.client.springcloud.init;

import java.util.Properties;
import java.util.concurrent.atomic.AtomicBoolean;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.dromara.soul.client.core.disruptor.SoulClientRegisterEventPublisher;
import org.dromara.soul.client.core.register.SoulClientRegisterRepositoryFactory;
import org.dromara.soul.common.enums.RpcTypeEnum;
import org.dromara.soul.register.client.api.SoulClientRegisterRepository;
import org.dromara.soul.register.common.config.SoulRegisterCenterConfig;
Expand All @@ -32,6 +29,9 @@
import org.springframework.core.env.Environment;
import org.springframework.lang.NonNull;

import java.util.Properties;
import java.util.concurrent.atomic.AtomicBoolean;

/**
* The type Context register listener.
*
Expand All @@ -55,8 +55,9 @@ public class ContextRegisterListener implements ApplicationListener<ContextRefre
*
* @param config the config
* @param env the env
* @param soulClientRegisterRepository the soulClientRegisterRepository
*/
public ContextRegisterListener(final SoulRegisterCenterConfig config, final Environment env) {
public ContextRegisterListener(final SoulRegisterCenterConfig config, final Environment env, final SoulClientRegisterRepository soulClientRegisterRepository) {
String registerType = config.getRegisterType();
String serverLists = config.getServerLists();
Properties props = config.getProps();
Expand All @@ -71,7 +72,6 @@ public ContextRegisterListener(final SoulRegisterCenterConfig config, final Envi
this.env = env;
this.contextPath = contextPath;
this.isFull = Boolean.parseBoolean(props.getProperty("isFull", "false"));
SoulClientRegisterRepository soulClientRegisterRepository = SoulClientRegisterRepositoryFactory.newInstance(config);
publisher.start(soulClientRegisterRepository);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,9 @@

package org.dromara.soul.client.springcloud.init;

import java.lang.reflect.Method;
import java.util.Objects;
import java.util.Properties;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.dromara.soul.client.core.disruptor.SoulClientRegisterEventPublisher;
import org.dromara.soul.client.core.register.SoulClientRegisterRepositoryFactory;
import org.dromara.soul.client.springcloud.annotation.SoulSpringCloudClient;
import org.dromara.soul.register.client.api.SoulClientRegisterRepository;
import org.dromara.soul.register.common.config.SoulRegisterCenterConfig;
Expand All @@ -41,6 +34,13 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.Method;
import java.util.Objects;
import java.util.Properties;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
* The type Soul client bean post processor.
*
Expand All @@ -64,8 +64,9 @@ public class SpringCloudClientBeanPostProcessor implements BeanPostProcessor {
*
* @param config the soul spring cloud config
* @param env the env
* @param soulClientRegisterRepository the soulClientRegisterRepository
*/
public SpringCloudClientBeanPostProcessor(final SoulRegisterCenterConfig config, final Environment env) {
public SpringCloudClientBeanPostProcessor(final SoulRegisterCenterConfig config, final Environment env, final SoulClientRegisterRepository soulClientRegisterRepository) {
String registerType = config.getRegisterType();
String serverLists = config.getServerLists();
Properties props = config.getProps();
Expand All @@ -81,7 +82,6 @@ public SpringCloudClientBeanPostProcessor(final SoulRegisterCenterConfig config,
this.env = env;
this.contextPath = contextPath;
this.isFull = Boolean.parseBoolean(props.getProperty("isFull", "false"));
SoulClientRegisterRepository soulClientRegisterRepository = SoulClientRegisterRepositoryFactory.newInstance(config);
publisher.start(soulClientRegisterRepository);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.dromara.soul.client.springcloud.init;

import org.dromara.soul.client.core.register.SoulClientRegisterRepositoryFactory;
import org.dromara.soul.register.common.config.SoulRegisterCenterConfig;
import org.junit.FixMethodOrder;
import org.junit.Test;
Expand Down Expand Up @@ -53,7 +54,7 @@ public void testNotFullRegister() {
mockRegisterCenter.setRegisterType("http");
mockRegisterCenter.setProps(properties);
when(env.getProperty("spring.application.name")).thenReturn("spring-cloud-test");
ContextRegisterListener contextRegisterListener = new ContextRegisterListener(mockRegisterCenter, env);
ContextRegisterListener contextRegisterListener = new ContextRegisterListener(mockRegisterCenter, env, SoulClientRegisterRepositoryFactory.newInstance(mockRegisterCenter));
ContextRefreshedEvent contextRefreshedEvent = mock(ContextRefreshedEvent.class);
contextRegisterListener.onApplicationEvent(contextRefreshedEvent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.dromara.soul.client.springcloud.init;

import org.dromara.soul.client.core.register.SoulClientRegisterRepositoryFactory;
import org.dromara.soul.client.springcloud.annotation.SoulSpringCloudClient;
import org.dromara.soul.register.client.http.utils.RegisterUtils;
import org.dromara.soul.register.common.config.SoulRegisterCenterConfig;
Expand Down Expand Up @@ -106,7 +107,7 @@ private SpringCloudClientBeanPostProcessor buildSpringCloudClientBeanPostProcess
mockRegisterCenter.setServerLists("http://127.0.0.1:8080");
mockRegisterCenter.setRegisterType("http");
mockRegisterCenter.setProps(properties);
return new SpringCloudClientBeanPostProcessor(mockRegisterCenter, env);
return new SpringCloudClientBeanPostProcessor(mockRegisterCenter, env, SoulClientRegisterRepositoryFactory.newInstance(mockRegisterCenter));
}

@RestController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@

package org.dromara.soul.client.springmvc.init;

import java.util.Properties;
import java.util.concurrent.atomic.AtomicBoolean;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.dromara.soul.client.core.disruptor.SoulClientRegisterEventPublisher;
import org.dromara.soul.client.core.register.SoulClientRegisterRepositoryFactory;
import org.dromara.soul.common.enums.RpcTypeEnum;
import org.dromara.soul.common.utils.IpUtils;
import org.dromara.soul.register.client.api.SoulClientRegisterRepository;
Expand All @@ -32,6 +29,9 @@
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.lang.NonNull;

import java.util.Properties;
import java.util.concurrent.atomic.AtomicBoolean;

/**
* The type Context register listener.
*/
Expand All @@ -55,8 +55,10 @@ public class ContextRegisterListener implements ApplicationListener<ContextRefre
/**
* Instantiates a new Context register listener.
*
* @param config the config
* @param soulClientRegisterRepository the soulClientRegisterRepository
*/
public ContextRegisterListener(final SoulRegisterCenterConfig config) {
public ContextRegisterListener(final SoulRegisterCenterConfig config, final SoulClientRegisterRepository soulClientRegisterRepository) {
String registerType = config.getRegisterType();
String serverLists = config.getServerLists();
Properties props = config.getProps();
Expand All @@ -73,7 +75,6 @@ public ContextRegisterListener(final SoulRegisterCenterConfig config) {
this.port = port;
this.contextPath = contextPath;
this.isFull = Boolean.parseBoolean(props.getProperty("isFull", "false"));
SoulClientRegisterRepository soulClientRegisterRepository = SoulClientRegisterRepositoryFactory.newInstance(config);
publisher.start(soulClientRegisterRepository);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.dromara.soul.client.core.disruptor.SoulClientRegisterEventPublisher;
import org.dromara.soul.client.core.register.SoulClientRegisterRepositoryFactory;
import org.dromara.soul.client.springmvc.annotation.SoulSpringMvcClient;
import org.dromara.soul.common.utils.IpUtils;
import org.dromara.soul.register.client.api.SoulClientRegisterRepository;
Expand Down Expand Up @@ -66,7 +65,7 @@ public class SpringMvcClientBeanPostProcessor implements BeanPostProcessor {
/**
* Instantiates a new Soul client bean post processor.
*/
public SpringMvcClientBeanPostProcessor(final SoulRegisterCenterConfig config) {
public SpringMvcClientBeanPostProcessor(final SoulRegisterCenterConfig config, final SoulClientRegisterRepository soulClientRegisterRepository) {
String registerType = config.getRegisterType();
String serverLists = config.getServerLists();
Properties props = config.getProps();
Expand All @@ -84,7 +83,6 @@ public SpringMvcClientBeanPostProcessor(final SoulRegisterCenterConfig config) {
this.contextPath = contextPath;
this.isFull = Boolean.parseBoolean(props.getProperty("isFull", "false"));
executorService = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
SoulClientRegisterRepository soulClientRegisterRepository = SoulClientRegisterRepositoryFactory.newInstance(config);
publisher.start(soulClientRegisterRepository);
}

Expand Down
Loading

0 comments on commit 070ede2

Please sign in to comment.