Search in sources :

Example 6 with LockBatchRequestBody

use of org.apache.rocketmq.common.protocol.body.LockBatchRequestBody in project rocketmq by apache.

the class RebalanceImpl method lock.

public boolean lock(final MessageQueue mq) {
    FindBrokerResult findBrokerResult = this.mQClientFactory.findBrokerAddressInSubscribe(mq.getBrokerName(), MixAll.MASTER_ID, true);
    if (findBrokerResult != null) {
        LockBatchRequestBody requestBody = new LockBatchRequestBody();
        requestBody.setConsumerGroup(this.consumerGroup);
        requestBody.setClientId(this.mQClientFactory.getClientId());
        requestBody.getMqSet().add(mq);
        try {
            Set<MessageQueue> lockedMq = this.mQClientFactory.getMQClientAPIImpl().lockBatchMQ(findBrokerResult.getBrokerAddr(), requestBody, 1000);
            for (MessageQueue mmqq : lockedMq) {
                ProcessQueue processQueue = this.processQueueTable.get(mmqq);
                if (processQueue != null) {
                    processQueue.setLocked(true);
                    processQueue.setLastLockTimestamp(System.currentTimeMillis());
                }
            }
            boolean lockOK = lockedMq.contains(mq);
            log.info("the message queue lock {}, {} {}", lockOK ? "OK" : "Failed", this.consumerGroup, mq);
            return lockOK;
        } catch (Exception e) {
            log.error("lockBatchMQ exception, " + mq, e);
        }
    }
    return false;
}
Also used : MessageQueue(org.apache.rocketmq.common.message.MessageQueue) LockBatchRequestBody(org.apache.rocketmq.common.protocol.body.LockBatchRequestBody) FindBrokerResult(org.apache.rocketmq.client.impl.FindBrokerResult)

Aggregations

MessageQueue (org.apache.rocketmq.common.message.MessageQueue)6 LockBatchRequestBody (org.apache.rocketmq.common.protocol.body.LockBatchRequestBody)6 FindBrokerResult (org.apache.rocketmq.client.impl.FindBrokerResult)4 HashSet (java.util.HashSet)2 Entry (java.util.Map.Entry)2 Set (java.util.Set)2 LockBatchResponseBody (org.apache.rocketmq.common.protocol.body.LockBatchResponseBody)2 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)2