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

The following examples show how to use com.alibaba.rocketmq.common.protocol.heartbeat.ConsumerData. 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: 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;
}