Search in sources :

Example 6 with SubscriptionData

use of org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class MQClientInstance method checkClientInBroker.

public void checkClientInBroker() throws MQClientException {
    Iterator<Entry<String, MQConsumerInner>> it = this.consumerTable.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, MQConsumerInner> entry = it.next();
        Set<SubscriptionData> subscriptionInner = entry.getValue().subscriptions();
        if (subscriptionInner == null || subscriptionInner.isEmpty()) {
            return;
        }
        for (SubscriptionData subscriptionData : subscriptionInner) {
            if (ExpressionType.isTagType(subscriptionData.getExpressionType())) {
                continue;
            }
            // may need to check one broker every cluster...
            // assume that the configs of every broker in cluster are the the same.
            String addr = findBrokerAddrByTopic(subscriptionData.getTopic());
            if (addr != null) {
                try {
                    this.getMQClientAPIImpl().checkClientInBroker(addr, entry.getKey(), this.clientId, subscriptionData, 3 * 1000);
                } catch (Exception e) {
                    if (e instanceof MQClientException) {
                        throw (MQClientException) e;
                    } else {
                        throw new MQClientException("Check client in broker error, maybe because you use " + subscriptionData.getExpressionType() + " to filter message, but server has not been upgraded to support!" + "This error would not affect the launch of consumer, but may has impact on message receiving if you " + "have use the new features which are not supported by server, please check the log!", e);
                    }
                }
            }
        }
    }
}
Also used : MQConsumerInner(org.apache.rocketmq.client.impl.consumer.MQConsumerInner) Entry(java.util.Map.Entry) SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData) MQClientException(org.apache.rocketmq.client.exception.MQClientException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RemotingException(org.apache.rocketmq.remoting.exception.RemotingException) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) MQClientException(org.apache.rocketmq.client.exception.MQClientException)

Example 7 with SubscriptionData

use of org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class MQClientInstance method uploadFilterClassSource.

private void uploadFilterClassSource() {
    Iterator<Entry<String, MQConsumerInner>> it = this.consumerTable.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, MQConsumerInner> next = it.next();
        MQConsumerInner consumer = next.getValue();
        if (ConsumeType.CONSUME_PASSIVELY == consumer.consumeType()) {
            Set<SubscriptionData> subscriptions = consumer.subscriptions();
            for (SubscriptionData sub : subscriptions) {
                if (sub.isClassFilterMode() && sub.getFilterClassSource() != null) {
                    final String consumerGroup = consumer.groupName();
                    final String className = sub.getSubString();
                    final String topic = sub.getTopic();
                    final String filterClassSource = sub.getFilterClassSource();
                    try {
                        this.uploadFilterClassToAllFilterServer(consumerGroup, className, topic, filterClassSource);
                    } catch (Exception e) {
                        log.error("uploadFilterClassToAllFilterServer Exception", e);
                    }
                }
            }
        }
    }
}
Also used : MQConsumerInner(org.apache.rocketmq.client.impl.consumer.MQConsumerInner) Entry(java.util.Map.Entry) SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData) MQClientException(org.apache.rocketmq.client.exception.MQClientException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RemotingException(org.apache.rocketmq.remoting.exception.RemotingException) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException)

Example 8 with SubscriptionData

use of org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class FilterAPI method buildSubscriptionData.

public static SubscriptionData buildSubscriptionData(final String consumerGroup, String topic, String subString) throws Exception {
    SubscriptionData subscriptionData = new SubscriptionData();
    subscriptionData.setTopic(topic);
    subscriptionData.setSubString(subString);
    if (null == subString || subString.equals(SubscriptionData.SUB_ALL) || subString.length() == 0) {
        subscriptionData.setSubString(SubscriptionData.SUB_ALL);
    } else {
        String[] tags = subString.split("\\|\\|");
        if (tags.length > 0) {
            for (String tag : tags) {
                if (tag.length() > 0) {
                    String trimString = tag.trim();
                    if (trimString.length() > 0) {
                        subscriptionData.getTagsSet().add(trimString);
                        subscriptionData.getCodeSet().add(trimString.hashCode());
                    }
                }
            }
        } else {
            throw new Exception("subString split error");
        }
    }
    return subscriptionData;
}
Also used : SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData)

Example 9 with SubscriptionData

use of org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class FilterAPI method build.

public static SubscriptionData build(final String topic, final String subString, final String type) throws Exception {
    if (ExpressionType.TAG.equals(type) || type == null) {
        return buildSubscriptionData(null, topic, subString);
    }
    if (subString == null || subString.length() < 1) {
        throw new IllegalArgumentException("Expression can't be null! " + type);
    }
    SubscriptionData subscriptionData = new SubscriptionData();
    subscriptionData.setTopic(topic);
    subscriptionData.setSubString(subString);
    subscriptionData.setExpressionType(type);
    return subscriptionData;
}
Also used : SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData)

Example 10 with SubscriptionData

use of org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class FilterAPITest method testBuildSubscriptionData.

@Test
public void testBuildSubscriptionData() throws Exception {
    SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(group, topic, subString);
    assertThat(subscriptionData.getTopic()).isEqualTo(topic);
    assertThat(subscriptionData.getSubString()).isEqualTo(subString);
    String[] tags = subString.split("\\|\\|");
    Set<String> tagSet = new HashSet<String>();
    for (String tag : tags) {
        tagSet.add(tag.trim());
    }
    assertThat(subscriptionData.getTagsSet()).isEqualTo(tagSet);
}
Also used : SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData) HashSet(java.util.HashSet) Test(org.junit.Test)

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