Java Code Examples for org.apache.rocketmq.common.filter.FilterAPI#buildSubscriptionData()

The following examples show how to use org.apache.rocketmq.common.filter.FilterAPI#buildSubscriptionData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultMQPushConsumerImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public void subscribe(String topic, String fullClassName, String filterClassSource) throws MQClientException {
    try {
        SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPushConsumer.getConsumerGroup(),
            topic, "*");
        subscriptionData.setSubString(fullClassName);
        subscriptionData.setClassFilterMode(true);
        subscriptionData.setFilterClassSource(filterClassSource);
        this.rebalanceImpl.getSubscriptionInner().put(topic, subscriptionData);
        if (this.mQClientFactory != null) {
            this.mQClientFactory.sendHeartbeatToAllBrokerWithLock();
        }

    } catch (Exception e) {
        throw new MQClientException("subscription exception", e);
    }
}
 
Example 2
Source File: DefaultLitePullConsumerImpl.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public synchronized void subscribe(String topic, String subExpression) throws MQClientException {
    try {
        if (topic == null || topic.equals("")) {
            throw new IllegalArgumentException("Topic can not be null or empty.");
        }
        setSubscriptionType(SubscriptionType.SUBSCRIBE);
        SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(defaultLitePullConsumer.getConsumerGroup(),
            topic, subExpression);
        this.rebalanceImpl.getSubscriptionInner().put(topic, subscriptionData);
        this.defaultLitePullConsumer.setMessageQueueListener(new MessageQueueListenerImpl());
        assignedMessageQueue.setRebalanceImpl(this.rebalanceImpl);
        if (serviceState == ServiceState.RUNNING) {
            this.mQClientFactory.sendHeartbeatToAllBrokerWithLock();
            updateTopicSubscribeInfoWhenSubscriptionChanged();
        }
    } catch (Exception e) {
        throw new MQClientException("subscribe exception", e);
    }
}
 
Example 3
Source File: DefaultMQPullConsumerImpl.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Override
public Set<SubscriptionData> subscriptions() {
    Set<SubscriptionData> result = new HashSet<SubscriptionData>();

    Set<String> topics = this.defaultMQPullConsumer.getRegisterTopics();
    if (topics != null) {
        synchronized (topics) {
            for (String t : topics) {
                SubscriptionData ms = null;
                try {
                    ms = FilterAPI.buildSubscriptionData(this.groupName(), t, SubscriptionData.SUB_ALL);
                } catch (Exception e) {
                    log.error("parse subscription error", e);
                }
                ms.setSubVersion(0L);
                result.add(ms);
            }
        }
    }

    return result;
}
 
Example 4
Source File: DefaultMQPushConsumerImpl.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
public void subscribe(String topic, String fullClassName, String filterClassSource) throws MQClientException {
    try {
        SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPushConsumer.getConsumerGroup(), //
            topic, "*");
        subscriptionData.setSubString(fullClassName);
        subscriptionData.setClassFilterMode(true);
        subscriptionData.setFilterClassSource(filterClassSource);
        this.rebalanceImpl.getSubscriptionInner().put(topic, subscriptionData);
        if (this.mQClientFactory != null) {
            this.mQClientFactory.sendHeartbeatToAllBrokerWithLock();
        }

    } catch (Exception e) {
        throw new MQClientException("subscription exception", e);
    }
}
 
Example 5
Source File: DefaultMQPushConsumerImpl.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
/**
 * 关注 topic。上传源代码
 * @param topic ;
 * @param fullClassName ;
 * @param filterClassSource ;
 * @throws MQClientException ;
 */
public void subscribe(String topic, String fullClassName, String filterClassSource) throws MQClientException {
    try {
        SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPushConsumer.getConsumerGroup(),
            topic, "*");
        subscriptionData.setSubString(fullClassName);
        subscriptionData.setClassFilterMode(true);
        subscriptionData.setFilterClassSource(filterClassSource);
        this.rebalanceImpl.getSubscriptionInner().put(topic, subscriptionData);
        if (this.mQClientFactory != null) {
            this.mQClientFactory.sendHeartbeatToAllBrokerWithLock();
        }

    } catch (Exception e) {
        throw new MQClientException("subscription exception", e);
    }
}
 
Example 6
Source File: DefaultMQPullConsumerImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Override
public Set<SubscriptionData> subscriptions() {
    Set<SubscriptionData> result = new HashSet<SubscriptionData>();

    Set<String> topics = this.defaultMQPullConsumer.getRegisterTopics();
    if (topics != null) {
        synchronized (topics) {
            for (String t : topics) {
                SubscriptionData ms = null;
                try {
                    ms = FilterAPI.buildSubscriptionData(this.groupName(), t, SubscriptionData.SUB_ALL);
                } catch (Exception e) {
                    log.error("parse subscription error", e);
                }
                ms.setSubVersion(0L);
                result.add(ms);
            }
        }
    }

    return result;
}
 
Example 7
Source File: DefaultMQPullConsumerImpl.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
private void copySubscription() throws MQClientException {
        try {
//            所有注册的topic
            Set<String> registerTopics = this.defaultMQPullConsumer.getRegisterTopics();
            if (registerTopics != null) {
                for (final String topic : registerTopics) {
//                    构建topic订阅配置=》
                    SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPullConsumer.getConsumerGroup(),
                        topic, SubscriptionData.SUB_ALL);
//                    存储topic订阅配置=》
                    this.rebalanceImpl.getSubscriptionInner().put(topic, subscriptionData);
                }
            }
        } catch (Exception e) {
            throw new MQClientException("subscription exception", e);
        }
    }
 
Example 8
Source File: DefaultMQPushConsumerImpl.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
public void subscribe(String topic, String fullClassName, String filterClassSource) throws MQClientException {
    try {
        SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPushConsumer.getConsumerGroup(),
            topic, "*");
        subscriptionData.setSubString(fullClassName);
        subscriptionData.setClassFilterMode(true);
        subscriptionData.setFilterClassSource(filterClassSource);
        this.rebalanceImpl.getSubscriptionInner().put(topic, subscriptionData);
        if (this.mQClientFactory != null) {
            this.mQClientFactory.sendHeartbeatToAllBrokerWithLock();
        }

    } catch (Exception e) {
        throw new MQClientException("subscription exception", e);
    }
}
 
Example 9
Source File: DefaultMQPullConsumerImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Override
public Set<SubscriptionData> subscriptions() {
    Set<SubscriptionData> result = new HashSet<SubscriptionData>();

    Set<String> topics = this.defaultMQPullConsumer.getRegisterTopics();
    if (topics != null) {
        synchronized (topics) {
            for (String t : topics) {
                SubscriptionData ms = null;
                try {
                    ms = FilterAPI.buildSubscriptionData(this.groupName(), t, SubscriptionData.SUB_ALL);
                } catch (Exception e) {
                    log.error("parse subscription error", e);
                }
                ms.setSubVersion(0L);
                result.add(ms);
            }
        }
    }

    return result;
}
 
Example 10
Source File: DefaultMQPushConsumerImpl.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public void subscribe(String topic, String fullClassName, String filterClassSource) throws MQClientException {
    try {
        SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPushConsumer.getConsumerGroup(),
            topic, "*");
        subscriptionData.setSubString(fullClassName);
        subscriptionData.setClassFilterMode(true);
        subscriptionData.setFilterClassSource(filterClassSource);
        this.rebalanceImpl.getSubscriptionInner().put(topic, subscriptionData);
        if (this.mQClientFactory != null) {
            this.mQClientFactory.sendHeartbeatToAllBrokerWithLock();
        }

    } catch (Exception e) {
        throw new MQClientException("subscription exception", e);
    }
}
 
Example 11
Source File: DefaultMQPullConsumerImpl.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
public void subscriptionAutomatically(final String topic) {
        if (!this.rebalanceImpl.getSubscriptionInner().containsKey(topic)) {
            try {
//                构建订阅数据=》
                SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPullConsumer.getConsumerGroup(),
                    topic, SubscriptionData.SUB_ALL);
                this.rebalanceImpl.subscriptionInner.putIfAbsent(topic, subscriptionData);
            } catch (Exception ignore) {
            }
        }
    }
 
Example 12
Source File: DefaultMQPushConsumerImpl.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public void subscribe(String topic, String subExpression) throws MQClientException {
    try {
        SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPushConsumer.getConsumerGroup(),
            topic, subExpression);
        this.rebalanceImpl.getSubscriptionInner().put(topic, subscriptionData);
        if (this.mQClientFactory != null) {
            this.mQClientFactory.sendHeartbeatToAllBrokerWithLock();
        }
    } catch (Exception e) {
        throw new MQClientException("subscription exception", e);
    }
}
 
Example 13
Source File: DefaultMQPushConsumerImpl.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
public void subscribe(String topic, String subExpression) throws MQClientException {
        try {
//            构建topic订阅数据,默认集群消费=》
            SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPushConsumer.getConsumerGroup(),
                topic, subExpression);
//            存储topic订阅数据=》
            this.rebalanceImpl.getSubscriptionInner().put(topic, subscriptionData);
            if (this.mQClientFactory != null) {
//                同步向所有的broker发送心跳监测=》
                this.mQClientFactory.sendHeartbeatToAllBrokerWithLock();
            }
        } catch (Exception e) {
            throw new MQClientException("subscription exception", e);
        }
    }
 
Example 14
Source File: DefaultMQPullConsumerImpl.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
private SubscriptionData getSubscriptionData(MessageQueue mq, String subExpression)
    throws MQClientException {

    if (null == mq) {
        throw new MQClientException("mq is null", null);
    }

    try {
        return FilterAPI.buildSubscriptionData(this.defaultMQPullConsumer.getConsumerGroup(),
            mq.getTopic(), subExpression);
    } catch (Exception e) {
        throw new MQClientException("parse subscription error", e);
    }
}
 
Example 15
Source File: DefaultMQPullConsumerImpl.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
/**
 * 这是神马意思?TODO
 * @param topic ;
 */
public void subscriptionAutomatically(final String topic) {
    if (!this.rebalanceImpl.getSubscriptionInner().containsKey(topic)) {
        try {
            SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPullConsumer.getConsumerGroup(),
                topic, SubscriptionData.SUB_ALL);
            this.rebalanceImpl.subscriptionInner.putIfAbsent(topic, subscriptionData);
        } catch (Exception ignore) {
        }
    }
}
 
Example 16
Source File: DefaultMQPullConsumerImpl.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
/**
 * 拷贝消费相关信息
 * @throws MQClientException ;
 */
private void copySubscription() throws MQClientException {
    try {
        Set<String> registerTopics = this.defaultMQPullConsumer.getRegisterTopics();
        if (registerTopics != null) {
            for (final String topic : registerTopics) {
                SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPullConsumer.getConsumerGroup(),
                    topic, SubscriptionData.SUB_ALL);
                this.rebalanceImpl.getSubscriptionInner().put(topic, subscriptionData);
            }
        }
    } catch (Exception e) {
        throw new MQClientException("subscription exception", e);
    }
}
 
Example 17
Source File: DefaultMQPushConsumerImpl.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
/**
 * 订阅
 */
public void subscribe(String topic, String subExpression) throws MQClientException {
    try {
        SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPushConsumer.getConsumerGroup(), //
            topic, subExpression);
        this.rebalanceImpl.getSubscriptionInner().put(topic, subscriptionData);
        if (this.mQClientFactory != null) {
            this.mQClientFactory.sendHeartbeatToAllBrokerWithLock();
        }
    } catch (Exception e) {
        throw new MQClientException("subscription exception", e);
    }
}
 
Example 18
Source File: DefaultMQPullConsumerImpl.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public void subscriptionAutomatically(final String topic) {
    if (!this.rebalanceImpl.getSubscriptionInner().containsKey(topic)) {
        try {
            SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPullConsumer.getConsumerGroup(), //
                topic, SubscriptionData.SUB_ALL);
            this.rebalanceImpl.subscriptionInner.putIfAbsent(topic, subscriptionData);
        } catch (Exception ignore) {
        }
    }
}
 
Example 19
Source File: DefaultMQPushConsumerImpl.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public void subscribe(String topic, String subExpression) throws MQClientException {
    try {
        SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPushConsumer.getConsumerGroup(),
            topic, subExpression);
        this.rebalanceImpl.getSubscriptionInner().put(topic, subscriptionData);
        if (this.mQClientFactory != null) {
            this.mQClientFactory.sendHeartbeatToAllBrokerWithLock();
        }
    } catch (Exception e) {
        throw new MQClientException("subscription exception", e);
    }
}
 
Example 20
Source File: DefaultMQPullConsumerImpl.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
private void copySubscription() throws MQClientException {
    try {
        Set<String> registerTopics = this.defaultMQPullConsumer.getRegisterTopics();
        if (registerTopics != null) {
            for (final String topic : registerTopics) {
                SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPullConsumer.getConsumerGroup(), //
                    topic, SubscriptionData.SUB_ALL);
                this.rebalanceImpl.getSubscriptionInner().put(topic, subscriptionData);
            }
        }
    } catch (Exception e) {
        throw new MQClientException("subscription exception", e);
    }
}