-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add support for publishing *RefreshEvent* when configuration changes
- fix remove ServiceInstance#metadata bug
- Loading branch information
Showing
8 changed files
with
111 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...onfig/src/main/java/me/ahoo/govern/config/spring/cloud/refresh/GovernConfigRefresher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package me.ahoo.govern.config.spring.cloud.refresh; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import me.ahoo.govern.config.ConfigChangedListener; | ||
import me.ahoo.govern.config.ConfigListenable; | ||
import me.ahoo.govern.config.NamespacedConfigId; | ||
import me.ahoo.govern.config.spring.cloud.GovernConfigProperties; | ||
import me.ahoo.govern.spring.cloud.GovernProperties; | ||
import org.springframework.beans.BeansException; | ||
import org.springframework.boot.context.event.ApplicationReadyEvent; | ||
import org.springframework.cloud.endpoint.event.RefreshEvent; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.ApplicationContextAware; | ||
import org.springframework.context.ApplicationListener; | ||
|
||
/** | ||
* @author ahoo wang | ||
*/ | ||
@Slf4j | ||
public class GovernConfigRefresher implements ApplicationListener<ApplicationReadyEvent>, ApplicationContextAware { | ||
private ApplicationContext applicationContext; | ||
private final ConfigListenable configListenable; | ||
private final GovernProperties governProperties; | ||
private final GovernConfigProperties configProperties; | ||
private final Listener listener; | ||
|
||
public GovernConfigRefresher( | ||
GovernProperties governProperties, | ||
GovernConfigProperties configProperties, | ||
ConfigListenable configListenable) { | ||
this.configListenable = configListenable; | ||
this.governProperties = governProperties; | ||
this.configProperties = configProperties; | ||
this.listener = new Listener(); | ||
} | ||
|
||
@Override | ||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | ||
this.applicationContext = applicationContext; | ||
} | ||
|
||
/** | ||
* Handle an application event. | ||
* | ||
* @param event the event to respond to | ||
*/ | ||
@Override | ||
public void onApplicationEvent(ApplicationReadyEvent event) { | ||
configListenable.addListener(NamespacedConfigId.of(governProperties.getNamespace(), configProperties.getConfigId()), listener); | ||
} | ||
|
||
class Listener implements ConfigChangedListener { | ||
@Override | ||
public void onChange(NamespacedConfigId namespacedConfigId, String op) { | ||
if (log.isInfoEnabled()) { | ||
log.info("Refresh - Govern-Service - configId:[{}] - [{}]", configProperties.getConfigId(), op); | ||
} | ||
applicationContext.publishEvent( | ||
new RefreshEvent(this, op, "Refresh Govern-Service config")); | ||
} | ||
} | ||
} |