com.alibaba.rocketmq.common.protocol.heartbeat.ConsumeType Java Examples

The following examples show how to use com.alibaba.rocketmq.common.protocol.heartbeat.ConsumeType. 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: ConsumerManager.java    From RocketMQ-Master-analyze with Apache License 2.0 6 votes vote down vote up
/**
 * 注册消费者 返回是否有变化
 */
public boolean registerConsumer(final String group, final ClientChannelInfo clientChannelInfo,
        ConsumeType consumeType, MessageModel messageModel, ConsumeFromWhere consumeFromWhere,
        final Set<SubscriptionData> subList) {
    ConsumerGroupInfo consumerGroupInfo = this.consumerTable.get(group);
    if (null == consumerGroupInfo) {
        ConsumerGroupInfo tmp = new ConsumerGroupInfo(group, consumeType, messageModel, consumeFromWhere);
        ConsumerGroupInfo prev = this.consumerTable.putIfAbsent(group, tmp);
        consumerGroupInfo = prev != null ? prev : tmp;
    }

    boolean r1 = consumerGroupInfo.updateChannel(clientChannelInfo, consumeType, messageModel,
        consumeFromWhere);
    boolean r2 = consumerGroupInfo.updateSubscription(subList);

    if (r1 || r2) {
        // ConsumerId列表变化,通知所有Consumer
        this.consumerIdsChangeListener.consumerIdsChanged(group, consumerGroupInfo.getAllChannel());
    }

    return r1 || r2;
}
 
Example #2
Source File: ConsumerManager.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public boolean registerConsumer(final String group, final ClientChannelInfo clientChannelInfo,
                                ConsumeType consumeType, MessageModel messageModel, ConsumeFromWhere consumeFromWhere,
                                final Set<SubscriptionData> subList) {

    ConsumerGroupInfo consumerGroupInfo = this.consumerTable.get(group);
    if (null == consumerGroupInfo) {
        ConsumerGroupInfo tmp = new ConsumerGroupInfo(group, consumeType, messageModel, consumeFromWhere);
        ConsumerGroupInfo prev = this.consumerTable.putIfAbsent(group, tmp);
        consumerGroupInfo = prev != null ? prev : tmp;
    }

    boolean r1 =
            consumerGroupInfo.updateChannel(clientChannelInfo, consumeType, messageModel,
                    consumeFromWhere);
    boolean r2 = consumerGroupInfo.updateSubscription(subList);

    if (r1 || r2) {
        this.consumerIdsChangeListener.consumerIdsChanged(group, consumerGroupInfo.getAllChannel());
    }

    return r1 || r2;
}
 
Example #3
Source File: ConsumerGroupInfo.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public ConsumerGroupInfo(String groupName, ConsumeType consumeType, MessageModel messageModel,
                         ConsumeFromWhere consumeFromWhere) {
    this.groupName = groupName;
    this.consumeType = consumeType;
    this.messageModel = messageModel;
    this.consumeFromWhere = consumeFromWhere;
}
 
Example #4
Source File: ConsumerGroupInfo.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
/**
 * 更新netty连接 返回值表示是否发生变更
 */
public boolean updateChannel(final ClientChannelInfo infoNew, ConsumeType consumeType,
        MessageModel messageModel, ConsumeFromWhere consumeFromWhere) {
    boolean updated = false;
    this.consumeType = consumeType;
    this.messageModel = messageModel;
    this.consumeFromWhere = consumeFromWhere;

    ClientChannelInfo infoOld = this.channelInfoTable.get(infoNew.getChannel());
    if (null == infoOld) {
        ClientChannelInfo prev = this.channelInfoTable.put(infoNew.getChannel(), infoNew);
        // 判断是否插入成功
        if (null == prev) {
            log.info("new consumer connected, group: {} {} {} channel: {}", this.groupName, consumeType,
                messageModel, infoNew.toString());
            updated = true;
        }

        infoOld = infoNew;
    }
    else {
        if (!infoOld.getClientId().equals(infoNew.getClientId())) {
            log.error(
                "[BUG] consumer channel exist in broker, but clientId not equal. GROUP: {} OLD: {} NEW: {} ",
                this.groupName, //
                infoOld.toString(), //
                infoNew.toString());
            this.channelInfoTable.put(infoNew.getChannel(), infoNew);
        }
    }

    this.lastUpdateTimestamp = System.currentTimeMillis();
    infoOld.setLastUpdateTimestamp(this.lastUpdateTimestamp);

    return updated;
}
 
Example #5
Source File: ConsumerGroupInfo.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
public ConsumerGroupInfo(String groupName, ConsumeType consumeType, MessageModel messageModel,
        ConsumeFromWhere consumeFromWhere) {
    this.groupName = groupName;
    this.consumeType = consumeType;
    this.messageModel = messageModel;
    this.consumeFromWhere = consumeFromWhere;
}
 
Example #6
Source File: ConsumerGroupInfo.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public boolean updateChannel(final ClientChannelInfo infoNew, ConsumeType consumeType,
                             MessageModel messageModel, ConsumeFromWhere consumeFromWhere) {
    boolean updated = false;
    this.consumeType = consumeType;
    this.messageModel = messageModel;
    this.consumeFromWhere = consumeFromWhere;

    ClientChannelInfo infoOld = this.channelInfoTable.get(infoNew.getChannel());
    if (null == infoOld) {
        ClientChannelInfo prev = this.channelInfoTable.put(infoNew.getChannel(), infoNew);
        if (null == prev) {
            log.info("new consumer connected, group: {} {} {} channel: {}", this.groupName, consumeType,
                    messageModel, infoNew.toString());
            updated = true;
        }

        infoOld = infoNew;
    } else {
        if (!infoOld.getClientId().equals(infoNew.getClientId())) {
            log.error(
                    "[BUG] consumer channel exist in broker, but clientId not equal. GROUP: {} OLD: {} NEW: {} ",
                    this.groupName,//
                    infoOld.toString(),//
                    infoNew.toString());
            this.channelInfoTable.put(infoNew.getChannel(), infoNew);
        }
    }

    this.lastUpdateTimestamp = System.currentTimeMillis();
    infoOld.setLastUpdateTimestamp(this.lastUpdateTimestamp);

    return updated;
}
 
Example #7
Source File: ConsumerManager.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 把 消费者(用clientChannelInfo 标识) 注册到指定的消费者分组(group),, 并且包含订阅元数据。
 * (消费类型, 消费模式, 位点类型,订阅的topic列表 。)
 * @param group
 * @param clientChannelInfo
 * @param consumeType
 * @param messageModel
 * @param consumeFromWhere
 * @param subList
 * @return
 */
public boolean registerConsumer(final String group, final ClientChannelInfo clientChannelInfo,
        ConsumeType consumeType, MessageModel messageModel, ConsumeFromWhere consumeFromWhere,
        final Set<SubscriptionData> subList) {
    ConsumerGroupInfo consumerGroupInfo = this.consumerTable.get(group);
    if (null == consumerGroupInfo) {
        ConsumerGroupInfo tmp = new ConsumerGroupInfo(group, consumeType, messageModel, consumeFromWhere);
        ConsumerGroupInfo prev = this.consumerTable.putIfAbsent(group, tmp);
        consumerGroupInfo = prev != null ? prev : tmp;
    }

    //把消费者通道(对应一个clientid ,默认clientip@processid.)注册到消费者分组下。
    boolean r1 =
            consumerGroupInfo.updateChannel(clientChannelInfo, consumeType, messageModel,
                consumeFromWhere);
    boolean r2 = consumerGroupInfo.updateSubscription(subList);

    if (r1 || r2) { //消费者被加入到消费者分组(r1) || 消费者分组增加或者删除了对topic的订阅 , 则给分组中的所有消费者发送
        //消费者id的变更通知, 启动client的rebalance (但这里有一点疑问, 如果消费者退出消费者分组,也应该启动消费者id 的变更通知的。
        // 仔细想一下,因为这里是消费者注册操作, 所以当然是消费者加入消费者分组!!!而消费者退出则应该通过其他的心跳操作来解决。

        //所谓rebalance ,以集群消费为例,其实就是一个消费者分组中的消费者要分摊消费topic下的所有消息。
        //而具体的rebalance算法是按照topic来做的 ,具体是:
        //每一个消费者client 收到reblance指令以后,看自己订阅了哪些topic ,然后按topic分别做rebalance .

        //而每一个topic内的rebalance操作如下:
        //先从client本地缓存的路由表中获取topic归属的brokername下的broker master .
        //然后问broker master要订阅者clientid列表, 然后把topic下的消费队列按均摊算法大致均匀分配给各个clientid ,
        //退出某一个队列的消费者放手(把位点更新到broker)  , 而加入队列的消费者接手(把放手的那个消费者位点拿过来以拉的方式消费)。
        // )
        this.consumerIdsChangeListener.consumerIdsChanged(group, consumerGroupInfo.getAllChannel());
    }

    return r1 || r2;
}
 
Example #8
Source File: ConsumerGroupInfo.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
public ConsumerGroupInfo(String groupName, ConsumeType consumeType, MessageModel messageModel,
        ConsumeFromWhere consumeFromWhere) {
    this.groupName = groupName;
    this.consumeType = consumeType;
    this.messageModel = messageModel;
    this.consumeFromWhere = consumeFromWhere;
}
 
Example #9
Source File: ConsumerGroupInfo.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
public boolean updateChannel(final ClientChannelInfo infoNew, ConsumeType consumeType,
        MessageModel messageModel, ConsumeFromWhere consumeFromWhere) {
    boolean updated = false;
    this.consumeType = consumeType;
    this.messageModel = messageModel;
    this.consumeFromWhere = consumeFromWhere;

    ClientChannelInfo infoOld = this.channelInfoTable.get(infoNew.getChannel());
    if (null == infoOld) { //原来没有注册对应的通道。
        //把新的通道注册进来 , 先进入的线程能够进入if 分支。
        ClientChannelInfo prev = this.channelInfoTable.put(infoNew.getChannel(), infoNew);
        if (null == prev) {
            log.info("new consumer connected, group: {} {} {} channel: {}", this.groupName, consumeType,
                messageModel, infoNew.toString());
            updated = true;
        }

        infoOld = infoNew;
    }
    else { //必须是相同的clientid 才能更新消费者通道信息。
        if (!infoOld.getClientId().equals(infoNew.getClientId())) {
            log.error(
                "[BUG] consumer channel exist in broker, but clientId not equal. GROUP: {} OLD: {} NEW: {} ",
                this.groupName,//
                infoOld.toString(),//
                infoNew.toString());
            this.channelInfoTable.put(infoNew.getChannel(), infoNew); //clientid不同的时候 ,也认为是加入新的消费者通道信息。
        }
    }

    this.lastUpdateTimestamp = System.currentTimeMillis();
    infoOld.setLastUpdateTimestamp(this.lastUpdateTimestamp);

    return updated;
}
 
Example #10
Source File: ConsumerGroupInfo.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public ConsumeType getConsumeType() {
    return consumeType;
}
 
Example #11
Source File: RebalancePullImpl.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
@Override
public ConsumeType consumeType() {
    return ConsumeType.CONSUME_ACTIVELY;
}
 
Example #12
Source File: ConsumerConnection.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public void setConsumeType(ConsumeType consumeType) {
    this.consumeType = consumeType;
}
 
Example #13
Source File: ConsumerConnection.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public ConsumeType getConsumeType() {
    return consumeType;
}
 
Example #14
Source File: ConsumerGroupInfo.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public void setConsumeType(ConsumeType consumeType) {
    this.consumeType = consumeType;
}
 
Example #15
Source File: ConsumerProgressSubCommand.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public ConsumeType getConsumeType() {
    return consumeType;
}
 
Example #16
Source File: ConsumerProgressSubCommand.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public String messageModelDesc() {
    if (this.count != 0 && this.getConsumeType() == ConsumeType.CONSUME_PASSIVELY) {
        return this.getMessageModel().toString();
    }
    return "";
}
 
Example #17
Source File: ConsumerProgressSubCommand.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public void setConsumeType(ConsumeType consumeType) {
    this.consumeType = consumeType;
}
 
Example #18
Source File: ConsumerService.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public void setConsumeType(ConsumeType consumeType) {
    this.consumeType = consumeType;
}
 
Example #19
Source File: DefaultMQPushConsumerImpl.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
@Override
public ConsumeType consumeType() {
    return ConsumeType.CONSUME_PASSIVELY;
}
 
Example #20
Source File: DefaultMQPullConsumerImpl.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
@Override
public ConsumeType consumeType() {
    return ConsumeType.CONSUME_ACTIVELY;
}
 
Example #21
Source File: RebalancePushImpl.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
@Override
public ConsumeType consumeType() {
    return ConsumeType.CONSUME_PASSIVELY;
}
 
Example #22
Source File: ConsumerProgressSubCommand.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
public String consumeTypeDesc() {
    if (this.count != 0) {
        return this.getConsumeType() == ConsumeType.CONSUME_ACTIVELY ? "PULL" : "PUSH";
    }
    return "";
}
 
Example #23
Source File: ConsumerProgressSubCommand.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
public String messageModelDesc() {
    if (this.count != 0 && this.getConsumeType() == ConsumeType.CONSUME_PASSIVELY) {
        return this.getMessageModel().toString();
    }
    return "";
}
 
Example #24
Source File: ConsumerProgressSubCommand.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
public ConsumeType getConsumeType() {
    return consumeType;
}
 
Example #25
Source File: ConsumerProgressSubCommand.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
public void setConsumeType(ConsumeType consumeType) {
    this.consumeType = consumeType;
}
 
Example #26
Source File: ConsumerGroupInfo.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
public ConsumeType getConsumeType() {
    return consumeType;
}
 
Example #27
Source File: ConsumerGroupInfo.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
public void setConsumeType(ConsumeType consumeType) {
    this.consumeType = consumeType;
}
 
Example #28
Source File: ConsumerConnection.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
public ConsumeType getConsumeType() {
    return consumeType;
}
 
Example #29
Source File: ConsumerConnection.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
public void setConsumeType(ConsumeType consumeType) {
    this.consumeType = consumeType;
}
 
Example #30
Source File: ConsumerConnection.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
public void setConsumeType(ConsumeType consumeType) {
    this.consumeType = consumeType;
}