Search in sources :

Example 1 with MqWhiteListConfigEvent

use of com.pamirs.pradar.pressurement.agent.event.impl.MqWhiteListConfigEvent in project LinkAgent by shulieTech.

the class MQWhiteList method compareIsChangeAndSet.

@Override
public Boolean compareIsChangeAndSet(ApplicationConfig currentValue, Set<String> newValue) {
    final MqWhiteListConfigEvent mqWhiteListConfigEvent = new MqWhiteListConfigEvent(newValue);
    EventRouter.router().publish(mqWhiteListConfigEvent);
    Set<String> mqWhiteList = GlobalConfig.getInstance().getMqWhiteList();
    if (ObjectUtils.equals(mqWhiteList.size(), newValue.size()) && mqWhiteList.containsAll(newValue)) {
        return Boolean.FALSE;
    }
    // 仅对影子消费者禁用事件处理
    for (String s : mqWhiteList) {
        List<ShadowConsumerDisableInfo> disableInfos = new ArrayList<ShadowConsumerDisableInfo>();
        if (!newValue.contains(s)) {
            ShadowConsumerDisableInfo disableInfo = new ShadowConsumerDisableInfo();
            if (s.contains("@")) {
                // rabbitmq routing使用方式,配置为direct-exchange#queue1@queue1
                disableInfo.setTopic(s.split("@")[1]);
            } else if (s.contains("#")) {
                String[] topicGroup = s.split("#", 2);
                if (StringUtils.isBlank(topicGroup[0])) {
                    disableInfo.setTopic(topicGroup[1]);
                } else {
                    disableInfo.setTopic(topicGroup[0]);
                    disableInfo.setConsumerGroup(topicGroup[1]);
                }
            }
            disableInfos.add(disableInfo);
        }
        if (!disableInfos.isEmpty()) {
            EventRouter.router().publish(new ShadowConsumerDisableEvent(disableInfos));
        }
    }
    currentValue.setMqList(newValue);
    PradarSwitcher.turnConfigSwitcherOn(ConfigNames.MQ_WHITE_LIST);
    GlobalConfig.getInstance().setMqWhiteList(newValue);
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("publish mq whitelist config successful. config={}", newValue);
    }
    return Boolean.TRUE;
}
Also used : MqWhiteListConfigEvent(com.pamirs.pradar.pressurement.agent.event.impl.MqWhiteListConfigEvent) ArrayList(java.util.ArrayList) ShadowConsumerDisableEvent(com.pamirs.pradar.pressurement.agent.event.impl.ShadowConsumerDisableEvent) ShadowConsumerDisableInfo(com.pamirs.pradar.pressurement.agent.listener.model.ShadowConsumerDisableInfo)

Aggregations

MqWhiteListConfigEvent (com.pamirs.pradar.pressurement.agent.event.impl.MqWhiteListConfigEvent)1 ShadowConsumerDisableEvent (com.pamirs.pradar.pressurement.agent.event.impl.ShadowConsumerDisableEvent)1 ShadowConsumerDisableInfo (com.pamirs.pradar.pressurement.agent.listener.model.ShadowConsumerDisableInfo)1 ArrayList (java.util.ArrayList)1