Search in sources :

Example 6 with ShadowConsumerDisableInfo

use of com.pamirs.pradar.pressurement.agent.listener.model.ShadowConsumerDisableInfo in project LinkAgent by shulieTech.

the class ConsumerRegistry method addListener.

private static void addListener(final DefaultMQPushConsumer businessConsumer) {
    final PradarEventListener listener = new PradarEventListener() {

        @Override
        public EventResult onEvent(IEvent event) {
            if (event instanceof ClusterTestSwitchOnEvent) {
                try {
                    // 取出配置创建影子消费者
                    DefaultMQPushConsumer defaultMQPushConsumer = buildMQPushConsumer(businessConsumer);
                    if (defaultMQPushConsumer != null) {
                        defaultMQPushConsumer.start();
                    }
                } catch (MQClientException e) {
                    logger.error(e.getMessage());
                    return EventResult.error("alibaba-rocketmq-plugin-open", "Alibaba-RocketMQ PT Consumer start failed: " + e.getMessage());
                }
                return EventResult.success("alibaba-rocketmq-plugin-open");
            } else if (event instanceof ClusterTestSwitchOffEvent || event instanceof SilenceSwitchOnEvent) {
                return shutdownShadowConsumer(businessConsumer);
            } else if (event instanceof ShadowConsumerDisableEvent) {
                String group = businessConsumer.getConsumerGroup();
                Set<String> topics = businessConsumer.getDefaultMQPushConsumerImpl().getRebalanceImpl().getSubscriptionInner().keySet();
                for (String topic : topics) {
                    List<ShadowConsumerDisableInfo> disableInfos = ((ShadowConsumerDisableEvent) event).getTarget();
                    for (ShadowConsumerDisableInfo disableInfo : disableInfos) {
                        if (topic.equals(disableInfo.getTopic()) && group.equals(disableInfo.getConsumerGroup())) {
                            return shutdownShadowConsumer(businessConsumer);
                        }
                    }
                }
            }
            return EventResult.IGNORE;
        }

        @Override
        public int order() {
            return 4;
        }
    };
    PradarEventListener old = listeners.putIfAbsent(businessConsumer, listener);
    if (old == null) {
        EventRouter.router().addListener(listener);
    }
}
Also used : PradarEventListener(com.pamirs.pradar.pressurement.agent.listener.PradarEventListener) IEvent(com.pamirs.pradar.pressurement.agent.event.IEvent) ClusterTestSwitchOnEvent(com.pamirs.pradar.pressurement.agent.event.impl.ClusterTestSwitchOnEvent) SilenceSwitchOnEvent(com.pamirs.pradar.pressurement.agent.event.impl.SilenceSwitchOnEvent) DefaultMQPushConsumer(com.alibaba.rocketmq.client.consumer.DefaultMQPushConsumer) MQClientException(com.alibaba.rocketmq.client.exception.MQClientException) ShadowConsumerDisableEvent(com.pamirs.pradar.pressurement.agent.event.impl.ShadowConsumerDisableEvent) ClusterTestSwitchOffEvent(com.pamirs.pradar.pressurement.agent.event.impl.ClusterTestSwitchOffEvent) ShadowConsumerDisableInfo(com.pamirs.pradar.pressurement.agent.listener.model.ShadowConsumerDisableInfo)

Aggregations

ShadowConsumerDisableInfo (com.pamirs.pradar.pressurement.agent.listener.model.ShadowConsumerDisableInfo)6 ShadowConsumerDisableEvent (com.pamirs.pradar.pressurement.agent.event.impl.ShadowConsumerDisableEvent)5 ClusterTestSwitchOffEvent (com.pamirs.pradar.pressurement.agent.event.impl.ClusterTestSwitchOffEvent)4 SilenceSwitchOnEvent (com.pamirs.pradar.pressurement.agent.event.impl.SilenceSwitchOnEvent)4 IEvent (com.pamirs.pradar.pressurement.agent.event.IEvent)2 ClusterTestSwitchOnEvent (com.pamirs.pradar.pressurement.agent.event.impl.ClusterTestSwitchOnEvent)2 PradarEventListener (com.pamirs.pradar.pressurement.agent.listener.PradarEventListener)2 DefaultMQPushConsumer (com.alibaba.rocketmq.client.consumer.DefaultMQPushConsumer)1 MQClientException (com.alibaba.rocketmq.client.exception.MQClientException)1 MqWhiteListConfigEvent (com.pamirs.pradar.pressurement.agent.event.impl.MqWhiteListConfigEvent)1 ArrayList (java.util.ArrayList)1 DefaultMQPushConsumer (org.apache.rocketmq.client.consumer.DefaultMQPushConsumer)1 MQClientException (org.apache.rocketmq.client.exception.MQClientException)1 RebalanceImpl (org.apache.rocketmq.client.impl.consumer.RebalanceImpl)1