Java Code Examples for com.alibaba.rocketmq.common.protocol.heartbeat.SubscriptionData#setTopic()

The following examples show how to use com.alibaba.rocketmq.common.protocol.heartbeat.SubscriptionData#setTopic() . 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: FilterAPI.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
public static SubscriptionData buildSubscriptionData(final String consumerGroup, String topic,
        String subString) throws Exception {
    SubscriptionData subscriptionData = new SubscriptionData();
    subscriptionData.setTopic(topic);
    subscriptionData.setSubString(subString);

    /*为null ,* ,或者空字符串 都认为是订阅topic的所有消息。*/
    if (null == subString || subString.equals(SubscriptionData.SUB_ALL) || subString.length() == 0) {
        subscriptionData.setSubString(SubscriptionData.SUB_ALL);
    }
    else {
        //按双竖线切分tag表达式,得到多个tag , trim运算以后,得到每一个tag以及每一个tag的hashcode (因为在broker是用msgTag的hashcode
        // 来做过滤的。)
        String[] tags = subString.split("\\|\\|");
        if (tags != null && 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;
}
 
Example 2
Source File: FilterAPI.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
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 != null && 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;
}
 
Example 3
Source File: MQClientAPIImpl.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
/**
 * 注册client
 * 
 * @param addr
 * @param heartbeat
 * @param timeoutMillis
 * @return
 * @throws RemotingException
 * @throws InterruptedException
 */
public boolean registerClient(final String addr, final HeartbeatData heartbeat, final long timeoutMillis)
        throws RemotingException, InterruptedException {
    if (!UtilAll.isBlank(projectGroupPrefix)) {
        Set<ConsumerData> consumerDatas = heartbeat.getConsumerDataSet();
        for (ConsumerData consumerData : consumerDatas) {
            consumerData.setGroupName(
                VirtualEnvUtil.buildWithProjectGroup(consumerData.getGroupName(), projectGroupPrefix));
            Set<SubscriptionData> subscriptionDatas = consumerData.getSubscriptionDataSet();
            for (SubscriptionData subscriptionData : subscriptionDatas) {
                subscriptionData.setTopic(VirtualEnvUtil
                    .buildWithProjectGroup(subscriptionData.getTopic(), projectGroupPrefix));
            }
        }
        Set<ProducerData> producerDatas = heartbeat.getProducerDataSet();
        for (ProducerData producerData : producerDatas) {
            producerData.setGroupName(
                VirtualEnvUtil.buildWithProjectGroup(producerData.getGroupName(), projectGroupPrefix));
        }
    }

    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.HEART_BEAT, null);

    request.setBody(heartbeat.encode());
    RemotingCommand response = this.remotingClient.invokeSync(addr, request, timeoutMillis);
    return response.getCode() == ResponseCode.SUCCESS;
}
 
Example 4
Source File: FilterAPI.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
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 != null && 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;
}