成功ApolloListen
This commit is contained in:
parent
fe832e28b7
commit
9734ee1826
2
pom.xml
2
pom.xml
|
@ -18,7 +18,7 @@
|
|||
<description>Demo project for Yame User Gateway</description>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<java.version>1.11</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<spring-cloud.version>Greenwich.SR2</spring-cloud.version>
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
<description>Demo project for Gateway Service</description>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<java.version>1.11</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
@ -70,6 +70,12 @@
|
|||
<artifactId>usergw-api</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.ctrip.framework.apollo</groupId>
|
||||
<artifactId>apollo-client</artifactId>
|
||||
<version>1.4.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
|
|
@ -1,19 +1,26 @@
|
|||
package cn.ecpark.service.usergw;
|
||||
|
||||
import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;
|
||||
|
||||
import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfig;
|
||||
import org.springframework.beans.factory.annotation.Configurable;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@Configurable
|
||||
@ConfigurationProperties
|
||||
@SpringBootApplication
|
||||
@SpringBootConfiguration
|
||||
@EnableAutoConfiguration
|
||||
@EnableDubboConfig
|
||||
@ComponentScan("cn.ecpark.service.usergw")
|
||||
@EnableApolloConfig
|
||||
public class App {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package cn.ecpark.service.usergw.config;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Configurable;
|
||||
import org.springframework.cloud.gateway.event.RefreshRoutesEvent;
|
||||
import org.springframework.cloud.gateway.route.RouteDefinitionWriter;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
|
||||
import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
|
||||
import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;
|
||||
|
||||
@Slf4j
|
||||
@Configurable
|
||||
@Service
|
||||
@EnableApolloConfig
|
||||
public class ConfigApollo implements ApplicationEventPublisherAware {
|
||||
|
||||
private ApplicationEventPublisher publisher;
|
||||
|
||||
public void notifyChanged() {
|
||||
this.publisher.publishEvent(new RefreshRoutesEvent(this));
|
||||
}
|
||||
|
||||
@ApolloConfigChangeListener("gateway.yml")
|
||||
private void listenApolloChange(ConfigChangeEvent changeEvent) {
|
||||
log.warn(changeEvent.getNamespace());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
|
||||
this.publisher = applicationEventPublisher;
|
||||
}
|
||||
|
||||
}
|
|
@ -64,11 +64,7 @@ public class ConfigGateway implements RouteDefinitionLocator {
|
|||
ignoreKey.add("filters");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Flux<RouteDefinition> getRouteDefinitions() {
|
||||
// WebFluxConfigurationSupport a;
|
||||
defaultFilters.clear();
|
||||
private InputStream loadLocalFileConfig() {
|
||||
Object inputStream = null;
|
||||
String[] gatewayConfigPathList;
|
||||
if (yameConfigPath == null) {
|
||||
|
@ -83,9 +79,22 @@ public class ConfigGateway implements RouteDefinitionLocator {
|
|||
break;
|
||||
}
|
||||
}
|
||||
return (InputStream)inputStream;
|
||||
}
|
||||
|
||||
private InputStream loadApolloConfige() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Flux<RouteDefinition> getRouteDefinitions() {
|
||||
// WebFluxConfigurationSupport a;
|
||||
defaultFilters.clear();
|
||||
InputStream inputStream = loadLocalFileConfig();
|
||||
|
||||
if (inputStream != null) {
|
||||
Map<String, Object> configYaml = new Yaml().load((InputStream) inputStream);
|
||||
Map<String, Object> configYaml = new Yaml().load(inputStream);
|
||||
if (configYaml != null) {
|
||||
|
||||
List<String> defaultFiltersYaml = null;
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
|
||||
spring.application.name=gateway
|
||||
|
||||
app.id=gateway
|
||||
apollo.meta=http://127.0.0.1:8180
|
||||
|
||||
dubbo.scan.base-packages=cn.ecpark.service.usergw.impl
|
||||
dubbo.protocol.name=dubbo
|
||||
dubbo.protocol.port=20999
|
||||
|
@ -13,3 +17,5 @@ logging.file=logs/log
|
|||
|
||||
yame.config=gateway.yaml
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user