org.apache.rocketmq.client.impl.FindBrokerResult Java Examples

The following examples show how to use org.apache.rocketmq.client.impl.FindBrokerResult. 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: DefaultMQPullConsumerTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws Exception {
    pullConsumer = new DefaultMQPullConsumer(consumerGroup);
    pullConsumer.setNamesrvAddr("127.0.0.1:9876");
    pullConsumer.start();
    PullAPIWrapper pullAPIWrapper = pullConsumer.getDefaultMQPullConsumerImpl().getPullAPIWrapper();
    Field field = PullAPIWrapper.class.getDeclaredField("mQClientFactory");
    field.setAccessible(true);
    field.set(pullAPIWrapper, mQClientFactory);

    field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl");
    field.setAccessible(true);
    field.set(mQClientFactory, mQClientAPIImpl);

    when(mQClientFactory.findBrokerAddressInSubscribe(anyString(), anyLong(), anyBoolean())).thenReturn(new FindBrokerResult("127.0.0.1:10911", false));
}
 
Example #2
Source File: RebalanceImpl.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
public void unlock(final MessageQueue mq, final boolean oneway) {
//        按brokerName查询broker地址在订阅信息中=》
        FindBrokerResult findBrokerResult = this.mQClientFactory.findBrokerAddressInSubscribe(mq.getBrokerName(), MixAll.MASTER_ID, true);
        if (findBrokerResult != null) {
            UnlockBatchRequestBody requestBody = new UnlockBatchRequestBody();
            requestBody.setConsumerGroup(this.consumerGroup);
            requestBody.setClientId(this.mQClientFactory.getClientId());
            requestBody.getMqSet().add(mq);

            try {
//                解锁批量消息队列,1s超时=》
                this.mQClientFactory.getMQClientAPIImpl().unlockBatchMQ(findBrokerResult.getBrokerAddr(), requestBody, 1000, oneway);
                log.warn("unlock messageQueue. group:{}, clientId:{}, mq:{}",
                    this.consumerGroup,
                    this.mQClientFactory.getClientId(),
                    mq);
            } catch (Exception e) {
                log.error("unlockBatchMQ exception, " + mq, e);
            }
        }
    }
 
Example #3
Source File: DefaultMQPullConsumerTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws Exception {
    pullConsumer = new DefaultMQPullConsumer(consumerGroup);
    pullConsumer.setNamesrvAddr("127.0.0.1:9876");
    pullConsumer.start();
    PullAPIWrapper pullAPIWrapper = pullConsumer.getDefaultMQPullConsumerImpl().getPullAPIWrapper();
    Field field = PullAPIWrapper.class.getDeclaredField("mQClientFactory");
    field.setAccessible(true);
    field.set(pullAPIWrapper, mQClientFactory);

    field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl");
    field.setAccessible(true);
    field.set(mQClientFactory, mQClientAPIImpl);

    when(mQClientFactory.findBrokerAddressInSubscribe(anyString(), anyLong(), anyBoolean())).thenReturn(new FindBrokerResult("127.0.0.1:10911", false));
}
 
Example #4
Source File: RebalanceImpl.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
public void unlock(final MessageQueue mq, final boolean oneway) {
    FindBrokerResult findBrokerResult = this.mQClientFactory.findBrokerAddressInSubscribe(mq.getBrokerName(), MixAll.MASTER_ID, true);
    if (findBrokerResult != null) {
        UnlockBatchRequestBody requestBody = new UnlockBatchRequestBody();
        requestBody.setConsumerGroup(this.consumerGroup);
        requestBody.setClientId(this.mQClientFactory.getClientId());
        requestBody.getMqSet().add(mq);

        try {
            this.mQClientFactory.getMQClientAPIImpl().unlockBatchMQ(findBrokerResult.getBrokerAddr(), requestBody, 1000, oneway);
            log.warn("unlock messageQueue. group:{}, clientId:{}, mq:{}", //
                this.consumerGroup, //
                this.mQClientFactory.getClientId(), //
                mq);
        } catch (Exception e) {
            log.error("unlockBatchMQ exception, " + mq, e);
        }
    }
}
 
Example #5
Source File: RemoteBrokerOffsetStore.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
private long fetchConsumeOffsetFromBroker(MessageQueue mq) 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) {
        QueryConsumerOffsetRequestHeader requestHeader = new QueryConsumerOffsetRequestHeader();
        requestHeader.setTopic(mq.getTopic());
        requestHeader.setConsumerGroup(this.groupName);
        requestHeader.setQueueId(mq.getQueueId());

        return this.mQClientFactory.getMQClientAPIImpl().queryConsumerOffset(
            findBrokerResult.getBrokerAddr(), requestHeader, 1000 * 5);
    } else {
        throw new MQClientException("The broker[" + mq.getBrokerName() + "] not exist", null);
    }
}
 
Example #6
Source File: RebalanceImpl.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public void unlock(final MessageQueue mq, final boolean oneway) {
    FindBrokerResult findBrokerResult = this.mQClientFactory.findBrokerAddressInSubscribe(mq.getBrokerName(), MixAll.MASTER_ID, true);
    if (findBrokerResult != null) {
        UnlockBatchRequestBody requestBody = new UnlockBatchRequestBody();
        requestBody.setConsumerGroup(this.consumerGroup);
        requestBody.setClientId(this.mQClientFactory.getClientId());
        requestBody.getMqSet().add(mq);

        try {
            this.mQClientFactory.getMQClientAPIImpl().unlockBatchMQ(findBrokerResult.getBrokerAddr(), requestBody, 1000, oneway);
            log.warn("unlock messageQueue. group:{}, clientId:{}, mq:{}",
                this.consumerGroup,
                this.mQClientFactory.getClientId(),
                mq);
        } catch (Exception e) {
            log.error("unlockBatchMQ exception, " + mq, e);
        }
    }
}
 
Example #7
Source File: RemoteBrokerOffsetStore.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
private long fetchConsumeOffsetFromBroker(MessageQueue mq) throws RemotingException, MQBrokerException,
    InterruptedException, MQClientException {
    FindBrokerResult findBrokerResult = this.mQClientFactory.findBrokerAddressInAdmin(mq.getBrokerName());
    if (null == findBrokerResult) {
        // TODO Here may be heavily overhead for Name Server,need tuning
        this.mQClientFactory.updateTopicRouteInfoFromNameServer(mq.getTopic());
        findBrokerResult = this.mQClientFactory.findBrokerAddressInAdmin(mq.getBrokerName());
    }

    if (findBrokerResult != null) {
        QueryConsumerOffsetRequestHeader requestHeader = new QueryConsumerOffsetRequestHeader();
        requestHeader.setTopic(mq.getTopic());
        requestHeader.setConsumerGroup(this.groupName);
        requestHeader.setQueueId(mq.getQueueId());

        return this.mQClientFactory.getMQClientAPIImpl().queryConsumerOffset(
            findBrokerResult.getBrokerAddr(), requestHeader, 1000 * 5);
    } else {
        throw new MQClientException("The broker[" + mq.getBrokerName() + "] not exist", null);
    }
}
 
Example #8
Source File: RebalanceImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public void unlock(final MessageQueue mq, final boolean oneway) {
    FindBrokerResult findBrokerResult = this.mQClientFactory.findBrokerAddressInSubscribe(mq.getBrokerName(), MixAll.MASTER_ID, true);
    if (findBrokerResult != null) {
        UnlockBatchRequestBody requestBody = new UnlockBatchRequestBody();
        requestBody.setConsumerGroup(this.consumerGroup);
        requestBody.setClientId(this.mQClientFactory.getClientId());
        requestBody.getMqSet().add(mq);

        try {
            this.mQClientFactory.getMQClientAPIImpl().unlockBatchMQ(findBrokerResult.getBrokerAddr(), requestBody, 1000, oneway);
            log.warn("unlock messageQueue. group:{}, clientId:{}, mq:{}",
                this.consumerGroup,
                this.mQClientFactory.getClientId(),
                mq);
        } catch (Exception e) {
            log.error("unlockBatchMQ exception, " + mq, e);
        }
    }
}
 
Example #9
Source File: DefaultMQPullConsumerTest.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws Exception {
    pullConsumer = new DefaultMQPullConsumer(consumerGroup);
    pullConsumer.setNamesrvAddr("127.0.0.1:9876");
    pullConsumer.start();
    PullAPIWrapper pullAPIWrapper = pullConsumer.getDefaultMQPullConsumerImpl().getPullAPIWrapper();
    Field field = PullAPIWrapper.class.getDeclaredField("mQClientFactory");
    field.setAccessible(true);
    field.set(pullAPIWrapper, mQClientFactory);

    field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl");
    field.setAccessible(true);
    field.set(mQClientFactory, mQClientAPIImpl);

    when(mQClientFactory.findBrokerAddressInSubscribe(anyString(), anyLong(), anyBoolean())).thenReturn(new FindBrokerResult("127.0.0.1:10911", false));
}
 
Example #10
Source File: RemoteBrokerOffsetStore.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
private long fetchConsumeOffsetFromBroker(MessageQueue mq) 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) {
            QueryConsumerOffsetRequestHeader requestHeader = new QueryConsumerOffsetRequestHeader();
            requestHeader.setTopic(mq.getTopic());
            requestHeader.setConsumerGroup(this.groupName);
            requestHeader.setQueueId(mq.getQueueId());

//            查询消费者offset=》
            return this.mQClientFactory.getMQClientAPIImpl().queryConsumerOffset(
                findBrokerResult.getBrokerAddr(), requestHeader, 1000 * 5);
        } else {
            throw new MQClientException("The broker[" + mq.getBrokerName() + "] not exist", null);
        }
    }
 
Example #11
Source File: DefaultMQPullConsumerTest.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws Exception {
    pullConsumer = new DefaultMQPullConsumer(consumerGroup);
    pullConsumer.setNamesrvAddr("127.0.0.1:9876");
    pullConsumer.start();
    PullAPIWrapper pullAPIWrapper = pullConsumer.getDefaultMQPullConsumerImpl().getPullAPIWrapper();
    Field field = PullAPIWrapper.class.getDeclaredField("mQClientFactory");
    field.setAccessible(true);
    field.set(pullAPIWrapper, mQClientFactory);

    field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl");
    field.setAccessible(true);
    field.set(mQClientFactory, mQClientAPIImpl);

    when(mQClientFactory.findBrokerAddressInSubscribe(anyString(), anyLong(), anyBoolean())).thenReturn(new FindBrokerResult("127.0.0.1:10911", false));
}
 
Example #12
Source File: DefaultMQPullConsumerTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws Exception {
    pullConsumer = new DefaultMQPullConsumer(consumerGroup);
    pullConsumer.setNamesrvAddr("127.0.0.1:9876");
    pullConsumer.start();
    PullAPIWrapper pullAPIWrapper = pullConsumer.getDefaultMQPullConsumerImpl().getPullAPIWrapper();
    Field field = PullAPIWrapper.class.getDeclaredField("mQClientFactory");
    field.setAccessible(true);
    field.set(pullAPIWrapper, mQClientFactory);

    field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl");
    field.setAccessible(true);
    field.set(mQClientFactory, mQClientAPIImpl);

    when(mQClientFactory.findBrokerAddressInSubscribe(anyString(), anyLong(), anyBoolean())).thenReturn(new FindBrokerResult("127.0.0.1:10911", false));
}
 
Example #13
Source File: RebalanceImpl.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
public void unlock(final MessageQueue mq, final boolean oneway) {
    FindBrokerResult findBrokerResult = this.mQClientFactory.findBrokerAddressInSubscribe(mq.getBrokerName(), MixAll.MASTER_ID, true);
    if (findBrokerResult != null) {
        UnlockBatchRequestBody requestBody = new UnlockBatchRequestBody();
        requestBody.setConsumerGroup(this.consumerGroup);
        requestBody.setClientId(this.mQClientFactory.getClientId());
        requestBody.getMqSet().add(mq);

        try {
            this.mQClientFactory.getMQClientAPIImpl().unlockBatchMQ(findBrokerResult.getBrokerAddr(), requestBody, 1000, oneway);
            log.warn("unlock messageQueue. group:{}, clientId:{}, mq:{}", //
                this.consumerGroup, //
                this.mQClientFactory.getClientId(), //
                mq);
        } catch (Exception e) {
            log.error("unlockBatchMQ exception, " + mq, e);
        }
    }
}
 
Example #14
Source File: RemoteBrokerOffsetStore.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
private long fetchConsumeOffsetFromBroker(MessageQueue mq) throws RemotingException, MQBrokerException,
    InterruptedException, MQClientException {
    FindBrokerResult findBrokerResult = this.mQClientFactory.findBrokerAddressInAdmin(mq.getBrokerName());
    if (null == findBrokerResult) {
        // TODO Here may be heavily overhead for Name Server,need tuning
        this.mQClientFactory.updateTopicRouteInfoFromNameServer(mq.getTopic());
        findBrokerResult = this.mQClientFactory.findBrokerAddressInAdmin(mq.getBrokerName());
    }

    if (findBrokerResult != null) {
        QueryConsumerOffsetRequestHeader requestHeader = new QueryConsumerOffsetRequestHeader();
        requestHeader.setTopic(mq.getTopic());
        requestHeader.setConsumerGroup(this.groupName);
        requestHeader.setQueueId(mq.getQueueId());

        return this.mQClientFactory.getMQClientAPIImpl().queryConsumerOffset(
            findBrokerResult.getBrokerAddr(), requestHeader, 1000 * 5);
    } else {
        throw new MQClientException("The broker[" + mq.getBrokerName() + "] not exist", null);
    }
}
 
Example #15
Source File: RemoteBrokerOffsetStore.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
/**
 * 拉取消费偏移量从Broker
 * @param mq mq
 * @return ;
 * @throws RemotingException ;
 * @throws MQBrokerException ;
 * @throws InterruptedException ;
 * @throws MQClientException ;
 */
private long fetchConsumeOffsetFromBroker(MessageQueue mq) 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) {
        QueryConsumerOffsetRequestHeader requestHeader = new QueryConsumerOffsetRequestHeader();
        requestHeader.setTopic(mq.getTopic());
        requestHeader.setConsumerGroup(this.groupName);
        requestHeader.setQueueId(mq.getQueueId());

        return this.mQClientFactory.getMQClientAPIImpl().queryConsumerOffset(
            findBrokerResult.getBrokerAddr(), requestHeader, 1000 * 5);
    } else {
        throw new MQClientException("The broker[" + mq.getBrokerName() + "] not exist", null);
    }
}
 
Example #16
Source File: RebalanceImpl.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
/**
 * 解锁一个队列
 * @param mq mq
 * @param oneway 是否oneway
 */
public void unlock(final MessageQueue mq, final boolean oneway) {
    FindBrokerResult findBrokerResult = this.mQClientFactory.findBrokerAddressInSubscribe(mq.getBrokerName(), MixAll.MASTER_ID, true);
    if (findBrokerResult != null) {
        UnlockBatchRequestBody requestBody = new UnlockBatchRequestBody();
        requestBody.setConsumerGroup(this.consumerGroup);
        requestBody.setClientId(this.mQClientFactory.getClientId());
        requestBody.getMqSet().add(mq);

        try {
            this.mQClientFactory.getMQClientAPIImpl().unlockBatchMQ(findBrokerResult.getBrokerAddr(), requestBody, 1000, oneway);
            log.warn("unlock messageQueue. group:{}, clientId:{}, mq:{}",
                this.consumerGroup,
                this.mQClientFactory.getClientId(),
                mq);
        } catch (Exception e) {
            log.error("unlockBatchMQ exception, " + mq, e);
        }
    }
}
 
Example #17
Source File: DefaultMQPullConsumerTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws Exception {
    pullConsumer = new DefaultMQPullConsumer(consumerGroup);
    pullConsumer.setNamesrvAddr("127.0.0.1:9876");
    pullConsumer.start();
    PullAPIWrapper pullAPIWrapper = pullConsumer.getDefaultMQPullConsumerImpl().getPullAPIWrapper();
    Field field = PullAPIWrapper.class.getDeclaredField("mQClientFactory");
    field.setAccessible(true);
    field.set(pullAPIWrapper, mQClientFactory);

    field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl");
    field.setAccessible(true);
    field.set(mQClientFactory, mQClientAPIImpl);

    when(mQClientFactory.findBrokerAddressInSubscribe(anyString(), anyLong(), anyBoolean())).thenReturn(new FindBrokerResult("127.0.0.1:10911", false));
}
 
Example #18
Source File: DefaultMQPullConsumerTest.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws Exception {
    pullConsumer = new DefaultMQPullConsumer(consumerGroup);
    pullConsumer.setNamesrvAddr("127.0.0.1:9876");
    pullConsumer.start();
    PullAPIWrapper pullAPIWrapper = pullConsumer.getDefaultMQPullConsumerImpl().getPullAPIWrapper();
    Field field = PullAPIWrapper.class.getDeclaredField("mQClientFactory");
    field.setAccessible(true);
    field.set(pullAPIWrapper, mQClientFactory);

    field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl");
    field.setAccessible(true);
    field.set(mQClientFactory, mQClientAPIImpl);

    when(mQClientFactory.findBrokerAddressInSubscribe(anyString(), anyLong(), anyBoolean())).thenReturn(new FindBrokerResult("127.0.0.1:10911", false));
}
 
Example #19
Source File: RemoteBrokerOffsetStore.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
/**
 * 从Broker上获取指定MessageQueue的消费Offset
 *
 * @param mq
 * @return
 * @throws RemotingException
 * @throws MQBrokerException
 * @throws InterruptedException
 * @throws MQClientException
 */
private long fetchConsumeOffsetFromBroker(MessageQueue mq) throws RemotingException, MQBrokerException,
    InterruptedException, MQClientException {
    FindBrokerResult findBrokerResult = this.mQClientFactory.findBrokerAddressInAdmin(mq.getBrokerName());
    if (null == findBrokerResult) {
        // TODO Here may be heavily overhead for Name Server,need tuning
        this.mQClientFactory.updateTopicRouteInfoFromNameServer(mq.getTopic());
        findBrokerResult = this.mQClientFactory.findBrokerAddressInAdmin(mq.getBrokerName());
    }

    if (findBrokerResult != null) {
        QueryConsumerOffsetRequestHeader requestHeader = new QueryConsumerOffsetRequestHeader();
        requestHeader.setTopic(mq.getTopic());
        requestHeader.setConsumerGroup(this.groupName);
        requestHeader.setQueueId(mq.getQueueId());

        return this.mQClientFactory.getMQClientAPIImpl().queryConsumerOffset(
            findBrokerResult.getBrokerAddr(), requestHeader, 1000 * 5);
    } else {
        throw new MQClientException("The broker[" + mq.getBrokerName() + "] not exist", null);
    }
}
 
Example #20
Source File: RebalanceImpl.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public void unlock(final MessageQueue mq, final boolean oneway) {
    FindBrokerResult findBrokerResult = this.mQClientFactory.findBrokerAddressInSubscribe(mq.getBrokerName(), MixAll.MASTER_ID, true);
    if (findBrokerResult != null) {
        UnlockBatchRequestBody requestBody = new UnlockBatchRequestBody();
        requestBody.setConsumerGroup(this.consumerGroup);
        requestBody.setClientId(this.mQClientFactory.getClientId());
        requestBody.getMqSet().add(mq);

        try {
            this.mQClientFactory.getMQClientAPIImpl().unlockBatchMQ(findBrokerResult.getBrokerAddr(), requestBody, 1000, oneway);
            log.warn("unlock messageQueue. group:{}, clientId:{}, mq:{}", //
                this.consumerGroup, //
                this.mQClientFactory.getClientId(), //
                mq);
        } catch (Exception e) {
            log.error("unlockBatchMQ exception, " + mq, e);
        }
    }
}
 
Example #21
Source File: RebalanceImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public void unlock(final MessageQueue mq, final boolean oneway) {
    FindBrokerResult findBrokerResult = this.mQClientFactory.findBrokerAddressInSubscribe(mq.getBrokerName(), MixAll.MASTER_ID, true);
    if (findBrokerResult != null) {
        UnlockBatchRequestBody requestBody = new UnlockBatchRequestBody();
        requestBody.setConsumerGroup(this.consumerGroup);
        requestBody.setClientId(this.mQClientFactory.getClientId());
        requestBody.getMqSet().add(mq);

        try {
            this.mQClientFactory.getMQClientAPIImpl().unlockBatchMQ(findBrokerResult.getBrokerAddr(), requestBody, 1000, oneway);
            log.warn("unlock messageQueue. group:{}, clientId:{}, mq:{}",
                this.consumerGroup,
                this.mQClientFactory.getClientId(),
                mq);
        } catch (Exception e) {
            log.error("unlockBatchMQ exception, " + mq, e);
        }
    }
}
 
Example #22
Source File: RemoteBrokerOffsetStore.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
private long fetchConsumeOffsetFromBroker(MessageQueue mq) 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) {
        QueryConsumerOffsetRequestHeader requestHeader = new QueryConsumerOffsetRequestHeader();
        requestHeader.setTopic(mq.getTopic());
        requestHeader.setConsumerGroup(this.groupName);
        requestHeader.setQueueId(mq.getQueueId());

        return this.mQClientFactory.getMQClientAPIImpl().queryConsumerOffset(
            findBrokerResult.getBrokerAddr(), requestHeader, 1000 * 5);
    } else {
        throw new MQClientException("The broker[" + mq.getBrokerName() + "] not exist", null);
    }
}
 
Example #23
Source File: DefaultMQPullConsumerTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws Exception {
    pullConsumer = new DefaultMQPullConsumer(consumerGroup);
    pullConsumer.setNamesrvAddr("127.0.0.1:9876");
    pullConsumer.start();
    PullAPIWrapper pullAPIWrapper = pullConsumer.getDefaultMQPullConsumerImpl().getPullAPIWrapper();
    Field field = PullAPIWrapper.class.getDeclaredField("mQClientFactory");
    field.setAccessible(true);
    field.set(pullAPIWrapper, mQClientFactory);

    field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl");
    field.setAccessible(true);
    field.set(mQClientFactory, mQClientAPIImpl);

    when(mQClientFactory.findBrokerAddressInSubscribe(anyString(), anyLong(), anyBoolean())).thenReturn(new FindBrokerResult("127.0.0.1:10911", false));
}
 
Example #24
Source File: RemoteBrokerOffsetStoreTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Before
public void init() {
    System.setProperty("rocketmq.client.localOffsetStoreDir", System.getProperty("java.io.tmpdir") + ".rocketmq_offsets");
    String clientId = new ClientConfig().buildMQClientId() + "#TestNamespace" + System.currentTimeMillis();
    when(mQClientFactory.getClientId()).thenReturn(clientId);
    when(mQClientFactory.findBrokerAddressInAdmin(brokerName)).thenReturn(new FindBrokerResult("127.0.0.1", false));
    when(mQClientFactory.getMQClientAPIImpl()).thenReturn(mqClientAPI);
}
 
Example #25
Source File: RebalanceImpl.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public void unlockAll(final boolean oneway) {
    HashMap<String, Set<MessageQueue>> brokerMqs = this.buildProcessQueueTableByBrokerName();

    for (final Map.Entry<String, Set<MessageQueue>> entry : brokerMqs.entrySet()) {
        final String brokerName = entry.getKey();
        final Set<MessageQueue> mqs = entry.getValue();

        if (mqs.isEmpty())
            continue;

        FindBrokerResult findBrokerResult = this.mQClientFactory.findBrokerAddressInSubscribe(brokerName, MixAll.MASTER_ID, true);
        if (findBrokerResult != null) {
            UnlockBatchRequestBody requestBody = new UnlockBatchRequestBody();
            requestBody.setConsumerGroup(this.consumerGroup);
            requestBody.setClientId(this.mQClientFactory.getClientId());
            requestBody.setMqSet(mqs);

            try {
                this.mQClientFactory.getMQClientAPIImpl().unlockBatchMQ(findBrokerResult.getBrokerAddr(), requestBody, 1000, oneway);

                for (MessageQueue mq : mqs) {
                    ProcessQueue processQueue = this.processQueueTable.get(mq);
                    if (processQueue != null) {
                        processQueue.setLocked(false);
                        log.info("the message queue unlock OK, Group: {} {}", this.consumerGroup, mq);
                    }
                }
            } catch (Exception e) {
                log.error("unlockBatchMQ exception, " + mqs, e);
            }
        }
    }
}
 
Example #26
Source File: RemoteBrokerOffsetStore.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #27
Source File: RebalanceImpl.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #28
Source File: RemoteBrokerOffsetStoreTest.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
@Before
public void init() {
    System.setProperty("rocketmq.client.localOffsetStoreDir", System.getProperty("java.io.tmpdir") + ".rocketmq_offsets");
    String clientId = new ClientConfig().buildMQClientId() + "#TestNamespace" + System.currentTimeMillis();
    when(mQClientFactory.getClientId()).thenReturn(clientId);
    when(mQClientFactory.findBrokerAddressInAdmin(brokerName)).thenReturn(new FindBrokerResult("127.0.0.1", false));
    when(mQClientFactory.getMQClientAPIImpl()).thenReturn(mqClientAPI);
}
 
Example #29
Source File: RemoteBrokerOffsetStoreTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Before
public void init() {
    System.setProperty("rocketmq.client.localOffsetStoreDir", System.getProperty("java.io.tmpdir") + ".rocketmq_offsets");
    String clientId = new ClientConfig().buildMQClientId() + "#TestNamespace" + System.currentTimeMillis();
    when(mQClientFactory.getClientId()).thenReturn(clientId);
    when(mQClientFactory.findBrokerAddressInAdmin(brokerName)).thenReturn(new FindBrokerResult("127.0.0.1", false));
    when(mQClientFactory.getMQClientAPIImpl()).thenReturn(mqClientAPI);
}
 
Example #30
Source File: MQClientInstance.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public FindBrokerResult findBrokerAddressInAdmin(final String brokerName) {
    String brokerAddr = null;
    boolean slave = false;
    boolean found = false;

    HashMap<Long/* brokerId */, String/* address */> map = this.brokerAddrTable.get(brokerName);
    if (map != null && !map.isEmpty()) {
        for (Map.Entry<Long, String> entry : map.entrySet()) {
            Long id = entry.getKey();
            brokerAddr = entry.getValue();
            if (brokerAddr != null) {
                found = true;
                if (MixAll.MASTER_ID == id) {
                    slave = false;
                } else {
                    slave = true;
                }
                break;

            }
        } // end of for
    }

    if (found) {
        return new FindBrokerResult(brokerAddr, slave, findBrokerVersion(brokerName, brokerAddr));
    }

    return null;
}