Search in sources :

Example 76 with SubscriptionData

use of org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData in project rocketmq by apache.

the class DefaultConsumerIdsChangeListener method handle.

@Override
public void handle(ConsumerGroupEvent event, String group, Object... args) {
    if (event == null) {
        return;
    }
    switch(event) {
        case CHANGE:
            if (args == null || args.length < 1) {
                return;
            }
            List<Channel> channels = (List<Channel>) args[0];
            if (channels != null && brokerController.getBrokerConfig().isNotifyConsumerIdsChangedEnable()) {
                for (Channel chl : channels) {
                    this.brokerController.getBroker2Client().notifyConsumerIdsChanged(chl, group);
                }
            }
            break;
        case UNREGISTER:
            this.brokerController.getConsumerFilterManager().unRegister(group);
            break;
        case REGISTER:
            if (args == null || args.length < 1) {
                return;
            }
            Collection<SubscriptionData> subscriptionDataList = (Collection<SubscriptionData>) args[0];
            this.brokerController.getConsumerFilterManager().register(group, subscriptionDataList);
            break;
        default:
            throw new RuntimeException("Unknown event " + event);
    }
}
Also used : Channel(io.netty.channel.Channel) SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData) Collection(java.util.Collection) List(java.util.List)

Example 77 with SubscriptionData

use of org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData in project rocketmq by apache.

the class ConsumerFilterManager method register.

public void register(final String consumerGroup, final Collection<SubscriptionData> subList) {
    for (SubscriptionData subscriptionData : subList) {
        register(subscriptionData.getTopic(), consumerGroup, subscriptionData.getSubString(), subscriptionData.getExpressionType(), subscriptionData.getSubVersion());
    }
    // make illegal topic dead.
    Collection<ConsumerFilterData> groupFilterData = getByGroup(consumerGroup);
    Iterator<ConsumerFilterData> iterator = groupFilterData.iterator();
    while (iterator.hasNext()) {
        ConsumerFilterData filterData = iterator.next();
        boolean exist = false;
        for (SubscriptionData subscriptionData : subList) {
            if (subscriptionData.getTopic().equals(filterData.getTopic())) {
                exist = true;
                break;
            }
        }
        if (!exist && !filterData.isDead()) {
            filterData.setDeadTime(System.currentTimeMillis());
            log.info("Consumer filter changed: {}, make illegal topic dead:{}", consumerGroup, filterData);
        }
    }
}
Also used : SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData)

Aggregations

SubscriptionData (org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData)77 MQBrokerException (org.apache.rocketmq.client.exception.MQBrokerException)24 MQClientException (org.apache.rocketmq.client.exception.MQClientException)24 RemotingException (org.apache.rocketmq.remoting.exception.RemotingException)24 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)18 HashSet (java.util.HashSet)16 ArrayList (java.util.ArrayList)14 List (java.util.List)12 Entry (java.util.Map.Entry)12 ConsumerConnection (org.apache.rocketmq.common.protocol.body.ConsumerConnection)12 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)12 HashMap (java.util.HashMap)10 Connection (org.apache.rocketmq.common.protocol.body.Connection)10 ConsumeStatus (org.apache.rocketmq.common.protocol.body.ConsumeStatus)10 ConsumerRunningInfo (org.apache.rocketmq.common.protocol.body.ConsumerRunningInfo)10 ProcessQueueInfo (org.apache.rocketmq.common.protocol.body.ProcessQueueInfo)10 Test (org.junit.Test)9 Field (java.lang.reflect.Field)8 MQClientAPIImpl (org.apache.rocketmq.client.impl.MQClientAPIImpl)8 MQClientInstance (org.apache.rocketmq.client.impl.factory.MQClientInstance)8