fix:fix routes of gateway doesn't refresh bug. (#163)
fix routes of gateway doesn't refresh bugpull/195/head
parent
88594487d0
commit
b693c8d16f
@ -1,15 +1,9 @@
|
||||
# Change Log
|
||||
---
|
||||
|
||||
- [Bugfix: fix router bug and add router example](https://github.com/Tencent/spring-cloud-tencent/pull/109)
|
||||
- [feat:add custom label resolver spi for rate limit](https://github.com/Tencent/spring-cloud-tencent/pull/107)
|
||||
- [feat:fix discovery weight param not set to register request bug](https://github.com/Tencent/spring-cloud-tencent/pull/104)
|
||||
- [Bugfix: fix causing cpu 100% when set ScheduledThreadPoolExecutor corePoolSize=0](https://github.com/Tencent/spring-cloud-tencent/pull/101)
|
||||
- [Refactor: refactor transfer metadata](https://github.com/Tencent/spring-cloud-tencent/pull/113)
|
||||
- [Bugfix: fix circuitbreaker http code greater than 400 as fail response bug](https://github.com/Tencent/spring-cloud-tencent/pull/118)
|
||||
- [Feat: optimize router dependency](https://github.com/Tencent/spring-cloud-tencent/pull/115)
|
||||
- [feat:add switch of polaris, discovery and register.](https://github.com/Tencent/spring-cloud-tencent/pull/129)
|
||||
- [Feature: Support custom rate limit reject response info](https://github.com/Tencent/spring-cloud-tencent/pull/153)
|
||||
- [Feature: Remove spring-javaformat-maven-plugin](https://github.com/Tencent/spring-cloud-tencent/pull/151)
|
||||
- [feat:optimize config server address.](https://github.com/Tencent/spring-cloud-tencent/pull/149)
|
||||
- [feat: override recover router config](https://github.com/Tencent/spring-cloud-tencent/pull/159)
|
||||
- [feat:refactor loadbalancer module as a basic module for router and circuit breaker.](https://github.com/Tencent/spring-cloud-tencent/pull/155)
|
||||
- [fix:fix routes of gateway doesn't refresh bug.](https://github.com/Tencent/spring-cloud-tencent/pull/163)
|
||||
|
@ -0,0 +1,11 @@
|
||||
# Change Log
|
||||
---
|
||||
|
||||
- [Bugfix: fix router bug and add router example](https://github.com/Tencent/spring-cloud-tencent/pull/109)
|
||||
- [feat:add custom label resolver spi for rate limit](https://github.com/Tencent/spring-cloud-tencent/pull/107)
|
||||
- [feat:fix discovery weight param not set to register request bug](https://github.com/Tencent/spring-cloud-tencent/pull/104)
|
||||
- [Bugfix: fix causing cpu 100% when set ScheduledThreadPoolExecutor corePoolSize=0](https://github.com/Tencent/spring-cloud-tencent/pull/101)
|
||||
- [Refactor: refactor transfer metadata](https://github.com/Tencent/spring-cloud-tencent/pull/113)
|
||||
- [Bugfix: fix circuitbreaker http code greater than 400 as fail response bug](https://github.com/Tencent/spring-cloud-tencent/pull/118)
|
||||
- [Feat: optimize router dependency](https://github.com/Tencent/spring-cloud-tencent/pull/115)
|
||||
- [feat:add switch of polaris, discovery and register.](https://github.com/Tencent/spring-cloud-tencent/pull/129)
|
@ -0,0 +1,62 @@
|
||||
package com.tencent.cloud.polaris.registry;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.tencent.polaris.api.plugin.registry.AbstractResourceEventListener;
|
||||
import com.tencent.polaris.api.pojo.RegistryCacheValue;
|
||||
import com.tencent.polaris.api.pojo.ServiceEventKey;
|
||||
import com.tencent.polaris.client.pojo.ServicesByProto;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.cloud.client.discovery.event.HeartbeatEvent;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
|
||||
/**
|
||||
* Change listener of Polaris service info.
|
||||
*
|
||||
* @author Haotian Zhang
|
||||
*/
|
||||
public class PolarisServiceChangeListener extends AbstractResourceEventListener implements ApplicationEventPublisherAware {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(PolarisServiceChangeListener.class);
|
||||
|
||||
private static final AtomicInteger INDEX = new AtomicInteger(0);
|
||||
|
||||
private ApplicationEventPublisher publisher;
|
||||
|
||||
@Override
|
||||
public void onResourceUpdated(ServiceEventKey svcEventKey, RegistryCacheValue oldValue,
|
||||
RegistryCacheValue newValue) {
|
||||
if (newValue.getEventType() != ServiceEventKey.EventType.SERVICE) {
|
||||
return;
|
||||
}
|
||||
if (oldValue instanceof ServicesByProto && newValue instanceof ServicesByProto) {
|
||||
LOG.debug("receive service={} change event", svcEventKey);
|
||||
Set<String> oldServiceInfoSet = ((ServicesByProto) oldValue).getServices().stream()
|
||||
.map(i -> i.getNamespace() + "::" + i.getService()).collect(Collectors.toSet());
|
||||
Set<String> newServiceInfoSet = ((ServicesByProto) newValue).getServices().stream()
|
||||
.map(i -> i.getNamespace() + "::" + i.getService()).collect(Collectors.toSet());
|
||||
|
||||
Sets.SetView<String> addServiceInfoSetView = Sets.difference(newServiceInfoSet, oldServiceInfoSet);
|
||||
Sets.SetView<String> deleteServiceInfoSetView = Sets.difference(oldServiceInfoSet, newServiceInfoSet);
|
||||
|
||||
if (addServiceInfoSetView.isEmpty() && deleteServiceInfoSetView.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
LOG.info("Service info is update. Add service of {}. Delete service of {}", addServiceInfoSetView, deleteServiceInfoSetView);
|
||||
|
||||
// Trigger reload of gateway route cache.
|
||||
this.publisher.publishEvent(new HeartbeatEvent(this, INDEX.getAndIncrement()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
|
||||
this.publisher = applicationEventPublisher;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue