use of com.alibaba.nacos.core.remote.control.TpsControlRuleChangeEvent in project nacos by alibaba.
the class InternalConfigChangeNotifier method onEvent.
@Override
public void onEvent(LocalDataChangeEvent event) {
String groupKey = event.groupKey;
String dataId = GroupKey.parseKey(groupKey)[0];
String group = GroupKey.parseKey(groupKey)[1];
if (DATA_ID_CONNECTION_LIMIT_RULE.equals(dataId) && NACOS_GROUP.equals(group)) {
try {
String content = loadLocalConfigLikeClient(dataId, group);
NotifyCenter.publishEvent(new ConnectionLimitRuleChangeEvent(content));
} catch (NacosException e) {
Loggers.REMOTE.error("connection limit rule load fail.", e);
}
}
if (dataId.startsWith(DATA_ID_TPS_CONTROL_RULE) && NACOS_GROUP.equals(group)) {
try {
String pointName = dataId.replaceFirst(DATA_ID_TPS_CONTROL_RULE, "");
String content = loadLocalConfigLikeClient(dataId, group);
NotifyCenter.publishEvent(new TpsControlRuleChangeEvent(pointName, content));
} catch (NacosException e) {
Loggers.REMOTE.error("connection limit rule load fail.", e);
}
}
}
use of com.alibaba.nacos.core.remote.control.TpsControlRuleChangeEvent in project nacos by alibaba.
the class InternalConfigChangeNotifierTest method testOnEvent.
@Test
public void testOnEvent() {
final String groupKey = GroupKey2.getKey("nacos.internal.tps.control_rule_1", "nacos", "tenant");
final String limitGroupKey = GroupKey2.getKey("nacos.internal.tps.nacos.internal.connection.limit.rule", "nacos", "tenant");
NotifyCenter.registerSubscriber(new Subscriber() {
@Override
public void onEvent(Event event) {
ConnectionLimitRuleChangeEvent connectionLimitRuleChangeEvent = (ConnectionLimitRuleChangeEvent) event;
Assert.assertEquals("content", connectionLimitRuleChangeEvent.getLimitRule());
}
@Override
public Class<? extends Event> subscribeType() {
return ConnectionLimitRuleChangeEvent.class;
}
});
NotifyCenter.registerSubscriber(new Subscriber() {
@Override
public void onEvent(Event event) {
TpsControlRuleChangeEvent tpsControlRuleChangeEvent = (TpsControlRuleChangeEvent) event;
Assert.assertEquals("content", tpsControlRuleChangeEvent.getRuleContent());
}
@Override
public Class<? extends Event> subscribeType() {
return TpsControlRuleChangeEvent.class;
}
});
internalConfigChangeNotifier.onEvent(new LocalDataChangeEvent(groupKey));
internalConfigChangeNotifier.onEvent(new LocalDataChangeEvent(limitGroupKey));
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Aggregations