-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathPropertiesRefresher.java
More file actions
74 lines (64 loc) · 2.81 KB
/
Copy pathPropertiesRefresher.java
File metadata and controls
74 lines (64 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.norland.suwp.keygen.eureka;
import com.ctrip.framework.apollo.model.ConfigChange;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
import com.netflix.discovery.DiscoveryManager;
import com.netflix.discovery.EurekaClient;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.impl.client.HttpClientBuilder;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
import org.springframework.cloud.context.scope.refresh.RefreshScope;
import org.springframework.cloud.context.scope.refresh.RefreshScopeRefreshedEvent;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.net.InetAddress;
import java.util.List;
import java.util.logging.Logger;
/**
* @author fengyuluo
* @createTime 10:20 2018/10/31
*/
@Slf4j
@Component
public class PropertiesRefresher implements ApplicationContextAware {
ApplicationContext applicationContext;
@Autowired
RefreshScope refreshScope;
@ApolloConfigChangeListener("suwp-commonms-dev")
public void onChange(ConfigChangeEvent changeEvent){
// boolean eurekaPropertiesChanged = false;
// for (String changedKey : changeEvent.changedKeys()) {
// if (changedKey.startsWith("eureka.")) {
// log.info("===============================================================");
// log.info("changedKey:{} value:{}",changedKey,changeEvent.getChange(changedKey));
// ConfigChange configChange = changeEvent.getChange(changedKey);
// configChange.getOldValue();
// eurekaPropertiesChanged = true;
// break;
// }
// }
refreshProperties(changeEvent);
// if (eurekaPropertiesChanged) {
// refreshEurekaProperties(changeEvent);
// }
}
public void refreshProperties(ConfigChangeEvent changeEvent){
this.applicationContext.publishEvent(new EnvironmentChangeEvent(changeEvent.changedKeys()));
refreshScope.refreshAll();
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
}