Search in sources :

Example 21 with FindBrokerResult

use of org.apache.rocketmq.client.impl.FindBrokerResult in project rocketmq by apache.

the class RemoteBrokerOffsetStore method updateConsumeOffsetToBroker.

/**
 * Update the Consumer Offset synchronously, once the Master is off, updated to Slave,
 * here need to be optimized.
 */
@Override
public void updateConsumeOffsetToBroker(MessageQueue mq, long offset, boolean isOneway) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
    FindBrokerResult findBrokerResult = this.mQClientFactory.findBrokerAddressInAdmin(mq.getBrokerName());
    if (null == findBrokerResult) {
        this.mQClientFactory.updateTopicRouteInfoFromNameServer(mq.getTopic());
        findBrokerResult = this.mQClientFactory.findBrokerAddressInAdmin(mq.getBrokerName());
    }
    if (findBrokerResult != null) {
        UpdateConsumerOffsetRequestHeader requestHeader = new UpdateConsumerOffsetRequestHeader();
        requestHeader.setTopic(mq.getTopic());
        requestHeader.setConsumerGroup(this.groupName);
        requestHeader.setQueueId(mq.getQueueId());
        requestHeader.setCommitOffset(offset);
        if (isOneway) {
            this.mQClientFactory.getMQClientAPIImpl().updateConsumerOffsetOneway(findBrokerResult.getBrokerAddr(), requestHeader, 1000 * 5);
        } else {
            this.mQClientFactory.getMQClientAPIImpl().updateConsumerOffset(findBrokerResult.getBrokerAddr(), requestHeader, 1000 * 5);
        }
    } else {
        throw new MQClientException("The broker[" + mq.getBrokerName() + "] not exist", null);
    }
}
Also used : UpdateConsumerOffsetRequestHeader(org.apache.rocketmq.common.protocol.header.UpdateConsumerOffsetRequestHeader) FindBrokerResult(org.apache.rocketmq.client.impl.FindBrokerResult) MQClientException(org.apache.rocketmq.client.exception.MQClientException)

Aggregations

FindBrokerResult (org.apache.rocketmq.client.impl.FindBrokerResult)21 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)8 HashSet (java.util.HashSet)6 MQClientException (org.apache.rocketmq.client.exception.MQClientException)6 Before (org.junit.Before)6 Field (java.lang.reflect.Field)4 Set (java.util.Set)4 PullAPIWrapper (org.apache.rocketmq.client.impl.consumer.PullAPIWrapper)4 MQClientInstance (org.apache.rocketmq.client.impl.factory.MQClientInstance)4 LockBatchRequestBody (org.apache.rocketmq.common.protocol.body.LockBatchRequestBody)4 UnlockBatchRequestBody (org.apache.rocketmq.common.protocol.body.UnlockBatchRequestBody)4 PullMessageRequestHeader (org.apache.rocketmq.common.protocol.header.PullMessageRequestHeader)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ConcurrentMap (java.util.concurrent.ConcurrentMap)3 InetSocketAddress (java.net.InetSocketAddress)2 Entry (java.util.Map.Entry)2 ClientConfig (org.apache.rocketmq.client.ClientConfig)2 PullResult (org.apache.rocketmq.client.consumer.PullResult)2