org.apache.rocketmq.client.exception.MQBrokerException Java Examples

The following examples show how to use org.apache.rocketmq.client.exception.MQBrokerException. 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 DDMQ with Apache License 2.0 6 votes vote down vote up
public long getMinOffset(final String addr, final String topic, final int queueId, final long timeoutMillis)
    throws RemotingException, MQBrokerException, InterruptedException {
    GetMinOffsetRequestHeader requestHeader = new GetMinOffsetRequestHeader();
    requestHeader.setTopic(topic);
    requestHeader.setQueueId(queueId);
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_MIN_OFFSET, requestHeader);

    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr),
        request, timeoutMillis);
    assert response != null;
    switch (response.getCode()) {
        case ResponseCode.SUCCESS: {
            GetMinOffsetResponseHeader responseHeader =
                (GetMinOffsetResponseHeader) response.decodeCommandCustomHeader(GetMinOffsetResponseHeader.class);

            return responseHeader.getOffset();
        }
        default:
            break;
    }

    throw new MQBrokerException(response.getCode(), response.getRemark());
}
 
Example #2
Source File: MQClientAPIImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public void unlockBatchMQ(
    final String addr,
    final UnlockBatchRequestBody requestBody,
    final long timeoutMillis,
    final boolean oneway
) throws RemotingException, MQBrokerException, InterruptedException {
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.UNLOCK_BATCH_MQ, null);

    request.setBody(requestBody.encode());

    if (oneway) {
        this.remotingClient.invokeOneway(addr, request, timeoutMillis);
    } else {
        RemotingCommand response = this.remotingClient
            .invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), request, timeoutMillis);
        switch (response.getCode()) {
            case ResponseCode.SUCCESS: {
                return;
            }
            default:
                break;
        }

        throw new MQBrokerException(response.getCode(), response.getRemark());
    }
}
 
Example #3
Source File: MQClientAPIImpl.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
public ConsumeStats getConsumeStats(final String addr, final String consumerGroup, final String topic,
    final long timeoutMillis)
    throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException,
    MQBrokerException {
    GetConsumeStatsRequestHeader requestHeader = new GetConsumeStatsRequestHeader();
    requestHeader.setConsumerGroup(consumerGroup);
    requestHeader.setTopic(topic);

    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_CONSUME_STATS, requestHeader);

    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr),
        request, timeoutMillis);
    switch (response.getCode()) {
        case ResponseCode.SUCCESS: {
            ConsumeStats consumeStats = ConsumeStats.decode(response.getBody(), ConsumeStats.class);
            return consumeStats;
        }
        default:
            break;
    }

    throw new MQBrokerException(response.getCode(), response.getRemark());
}
 
Example #4
Source File: DefaultMQAdminExtImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Override
public ConsumerConnection examineConsumerConnectionInfo(
    String consumerGroup) throws InterruptedException, MQBrokerException,
    RemotingException, MQClientException {
    ConsumerConnection result = new ConsumerConnection();
    String topic = MixAll.getRetryTopic(consumerGroup);
    List<BrokerData> brokers = this.examineTopicRouteInfo(topic).getBrokerDatas();
    BrokerData brokerData = brokers.get(random.nextInt(brokers.size()));
    String addr = null;
    if (brokerData != null) {
        addr = brokerData.selectBrokerAddr();
        if (StringUtils.isNotBlank(addr)) {
            result = this.mqClientInstance.getMQClientAPIImpl().getConsumerConnectionList(addr, consumerGroup, timeoutMillis);
        }
    }

    if (result.getConnectionSet().isEmpty()) {
        log.warn("the consumer group not online. brokerAddr={}, group={}", addr, consumerGroup);
        throw new MQClientException(ResponseCode.CONSUMER_NOT_ONLINE, "Not found the consumer group connection");
    }

    return result;
}
 
Example #5
Source File: DefaultMQAdminExtImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Override
public boolean cleanUnusedTopic(String cluster) throws RemotingConnectException, RemotingSendRequestException,
    RemotingTimeoutException, MQClientException, InterruptedException {
    boolean result = false;
    try {
        ClusterInfo clusterInfo = examineBrokerClusterInfo();
        if (null == cluster || "".equals(cluster)) {
            for (String targetCluster : clusterInfo.retrieveAllClusterNames()) {
                result = cleanUnusedTopicByCluster(clusterInfo, targetCluster);
            }
        } else {
            result = cleanUnusedTopicByCluster(clusterInfo, cluster);
        }
    } catch (MQBrokerException e) {
        log.error("cleanExpiredConsumerQueue error.", e);
    }

    return result;
}
 
Example #6
Source File: WipeWritePermSubCommandTest.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void init() throws NoSuchFieldException, IllegalAccessException, InterruptedException, RemotingTimeoutException, MQClientException, RemotingSendRequestException, RemotingConnectException, MQBrokerException, RemotingCommandException {
    mQClientAPIImpl = mock(MQClientAPIImpl.class);
    defaultMQAdminExt = new DefaultMQAdminExt();
    defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000);

    Field field = DefaultMQAdminExtImpl.class.getDeclaredField("mqClientInstance");
    field.setAccessible(true);
    field.set(defaultMQAdminExtImpl, mqClientInstance);
    field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl");
    field.setAccessible(true);
    field.set(mqClientInstance, mQClientAPIImpl);
    field = DefaultMQAdminExt.class.getDeclaredField("defaultMQAdminExtImpl");
    field.setAccessible(true);
    field.set(defaultMQAdminExt, defaultMQAdminExtImpl);

    List<String> result = new ArrayList<>();
    result.add("default-name-one");
    result.add("default-name-two");
    when(mqClientInstance.getMQClientAPIImpl().getNameServerAddressList()).thenReturn(result);
    when(mQClientAPIImpl.wipeWritePermOfBroker(anyString(), anyString(), anyLong())).thenReturn(6);
}
 
Example #7
Source File: MQClientAPIImpl.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
public SubscriptionGroupWrapper getAllSubscriptionGroup(final String brokerAddr,
    long timeoutMillis) throws InterruptedException,
    RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException {
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_SUBSCRIPTIONGROUP_CONFIG, null);
    RemotingCommand response = this.remotingClient
        .invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), brokerAddr), request, timeoutMillis);
    assert response != null;
    switch (response.getCode()) {
        case ResponseCode.SUCCESS: {
            return SubscriptionGroupWrapper.decode(response.getBody(), SubscriptionGroupWrapper.class);
        }
        default:
            break;
    }
    throw new MQBrokerException(response.getCode(), response.getRemark());
}
 
Example #8
Source File: MQClientAPIImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public long queryConsumerOffset(
    final String addr,
    final QueryConsumerOffsetRequestHeader requestHeader,
    final long timeoutMillis
) throws RemotingException, MQBrokerException, InterruptedException {
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.QUERY_CONSUMER_OFFSET, requestHeader);

    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr),
        request, timeoutMillis);
    assert response != null;
    switch (response.getCode()) {
        case ResponseCode.SUCCESS: {
            QueryConsumerOffsetResponseHeader responseHeader =
                (QueryConsumerOffsetResponseHeader) response.decodeCommandCustomHeader(QueryConsumerOffsetResponseHeader.class);

            return responseHeader.getOffset();
        }
        default:
            break;
    }

    throw new MQBrokerException(response.getCode(), response.getRemark());
}
 
Example #9
Source File: BrokerOuterAPI.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public String getAllDelayOffset(
    final String addr) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException,
    RemotingConnectException, MQBrokerException, UnsupportedEncodingException {
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_DELAY_OFFSET, null);
    RemotingCommand response = this.remotingClient.invokeSync(addr, request, getTimeout());
    assert response != null;
    switch (response.getCode()) {
        case ResponseCode.SUCCESS: {
            return new String(response.getBody(), MixAll.DEFAULT_CHARSET);
        }
        default:
            break;
    }

    throw new MQBrokerException(response.getCode(), response.getRemark());
}
 
Example #10
Source File: BatchMQProducer.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public void send(CarreraRequest request, MessageQueueSelector messageQueueSelector)
    throws RemotingException, MQClientException, InterruptedException, MQBrokerException {
    TopicPublishInfo topicInfo = clusterProducer.getRocketMQProducerByIndex(0).getDefaultMQProducerImpl().getTopicPublishInfoTable().get(request.getTopic());
    if (topicInfo == null || !topicInfo.ok()) { //new topic
        sendSingleMessage(request);
        return;
    }

    MessageQueue mq = messageQueueSelector.select(topicInfo.getMessageQueueList(), null, request);
    request.setMessageQueue(mq);

    requestQMap.computeIfAbsent(mq.getBrokerName(), _name -> {
        Deque<CarreraRequest> q = new ConcurrentLinkedDeque<>();
        addRequestQueue(q, _name, config.getMaxEncodeWorkerForEachBroker());
        return q;
    }).add(request);
}
 
Example #11
Source File: BrokerOuterAPI.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public TopicConfigSerializeWrapper getAllTopicConfig(
    final String addr) throws RemotingConnectException, RemotingSendRequestException,
    RemotingTimeoutException, InterruptedException, MQBrokerException {
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_TOPIC_CONFIG, null);

    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(true, addr), request, getTimeout());
    assert response != null;
    switch (response.getCode()) {
        case ResponseCode.SUCCESS: {
            return TopicConfigSerializeWrapper.decode(response.getBody(), TopicConfigSerializeWrapper.class);
        }
        default:
            break;
    }

    throw new MQBrokerException(response.getCode(), response.getRemark());
}
 
Example #12
Source File: MQClientAPIImpl.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
public TopicStatsTable getTopicStatsInfo(final String addr, final String topic,
    final long timeoutMillis) throws InterruptedException,
    RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException {
    GetTopicStatsInfoRequestHeader requestHeader = new GetTopicStatsInfoRequestHeader();
    requestHeader.setTopic(topic);

    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_TOPIC_STATS_INFO, requestHeader);

    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr),
        request, timeoutMillis);
    switch (response.getCode()) {
        case ResponseCode.SUCCESS: {
            TopicStatsTable topicStatsTable = TopicStatsTable.decode(response.getBody(), TopicStatsTable.class);
            return topicStatsTable;
        }
        default:
            break;
    }

    throw new MQBrokerException(response.getCode(), response.getRemark());
}
 
Example #13
Source File: QueryMsgByIdSubCommand.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
private void sendMsg(final DefaultMQAdminExt defaultMQAdminExt, final DefaultMQProducer defaultMQProducer,
    final String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
    try {
        MessageExt msg = defaultMQAdminExt.viewMessage(msgId);
        if (msg != null) {
            // resend msg by id
            System.out.printf("prepare resend msg. originalMsgId=%s", msgId);
            SendResult result = defaultMQProducer.send(msg);
            System.out.printf("%s", result);
        } else {
            System.out.printf("no message. msgId=%s", msgId);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #14
Source File: BrokerOuterAPI.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
public SubscriptionGroupWrapper getAllSubscriptionGroupConfig(
        final String addr) throws InterruptedException, RemotingTimeoutException,
        RemotingSendRequestException, RemotingConnectException, MQBrokerException {
        RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_SUBSCRIPTIONGROUP_CONFIG, null);
//        同步执行=》
        RemotingCommand response = this.remotingClient.invokeSync(addr, request, 3000);
        assert response != null;
        switch (response.getCode()) {
            case ResponseCode.SUCCESS: {
//                消息json解码
                return SubscriptionGroupWrapper.decode(response.getBody(), SubscriptionGroupWrapper.class);
            }
            default:
                break;
        }

        throw new MQBrokerException(response.getCode(), response.getRemark());
    }
 
Example #15
Source File: ConsumerConnectionSubCommandTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void init() throws NoSuchFieldException, IllegalAccessException, InterruptedException, RemotingTimeoutException, MQClientException, RemotingSendRequestException, RemotingConnectException, MQBrokerException {
    mQClientAPIImpl = mock(MQClientAPIImpl.class);
    defaultMQAdminExt = new DefaultMQAdminExt();
    defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000);

    Field field = DefaultMQAdminExtImpl.class.getDeclaredField("mqClientInstance");
    field.setAccessible(true);
    field.set(defaultMQAdminExtImpl, mqClientInstance);
    field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl");
    field.setAccessible(true);
    field.set(mqClientInstance, mQClientAPIImpl);
    field = DefaultMQAdminExt.class.getDeclaredField("defaultMQAdminExtImpl");
    field.setAccessible(true);
    field.set(defaultMQAdminExt, defaultMQAdminExtImpl);

    ConsumerConnection consumerConnection = new ConsumerConnection();
    consumerConnection.setConsumeType(ConsumeType.CONSUME_PASSIVELY);
    consumerConnection.setMessageModel(MessageModel.CLUSTERING);
    HashSet<Connection> connections = new HashSet<>();
    connections.add(new Connection());
    consumerConnection.setConnectionSet(connections);
    consumerConnection.setSubscriptionTable(new ConcurrentHashMap<String, SubscriptionData>());
    consumerConnection.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
    when(mQClientAPIImpl.getConsumerConnectionList(anyString(), anyString(), anyLong())).thenReturn(consumerConnection);
}
 
Example #16
Source File: DefaultMQPushConsumerTest.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@Test
public void testPullMessage_Success() throws InterruptedException, RemotingException, MQBrokerException {
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    final MessageExt[] messageExts = new MessageExt[1];
    pushConsumer.getDefaultMQPushConsumerImpl().setConsumeMessageService(new ConsumeMessageConcurrentlyService(pushConsumer.getDefaultMQPushConsumerImpl(), new MessageListenerConcurrently() {
        @Override
        public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs,
            ConsumeConcurrentlyContext context) {
            messageExts[0] = msgs.get(0);
            countDownLatch.countDown();
            return null;
        }
    }));

    PullMessageService pullMessageService = mQClientFactory.getPullMessageService();
    pullMessageService.executePullRequestImmediately(createPullRequest());
    countDownLatch.await();
    assertThat(messageExts[0].getTopic()).isEqualTo(topic);
    assertThat(messageExts[0].getBody()).isEqualTo(new byte[] {'a'});
}
 
Example #17
Source File: PullAPIWrapper.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public PullResult pullKernelImpl(
    final MessageQueue mq,
    final String subExpression,
    final long subVersion,
    final long offset,
    final int maxNums,
    final int sysFlag,
    final long commitOffset,
    final long brokerSuspendMaxTimeMillis,
    final long timeoutMillis,
    final CommunicationMode communicationMode,
    final PullCallback pullCallback
) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
    return pullKernelImpl(mq, subExpression, subVersion, offset, maxNums, sysFlag, commitOffset, brokerSuspendMaxTimeMillis,
        timeoutMillis, communicationMode, pullCallback, false);
}
 
Example #18
Source File: CommandUtil.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
public static Set<String> fetchMasterAndSlaveAddrByClusterName(final MQAdminExt adminExt, final String clusterName)
    throws InterruptedException, RemotingConnectException, RemotingTimeoutException,
    RemotingSendRequestException, MQBrokerException {
    Set<String> brokerAddressSet = new HashSet<String>();
    ClusterInfo clusterInfoSerializeWrapper = adminExt.examineBrokerClusterInfo();
    Set<String> brokerNameSet = clusterInfoSerializeWrapper.getClusterAddrTable().get(clusterName);
    if (brokerNameSet != null) {
        for (String brokerName : brokerNameSet) {
            BrokerData brokerData = clusterInfoSerializeWrapper.getBrokerAddrTable().get(brokerName);
            if (brokerData != null) {
                final Collection<String> addrs = brokerData.getBrokerAddrs().values();
                brokerAddressSet.addAll(addrs);
            }
        }
    } else {
        System.out.printf("[error] %s", ERROR_MESSAGE);
    }

    return brokerAddressSet;
}
 
Example #19
Source File: MQClientAPIImpl.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
public Properties getBrokerConfig(final String addr, final long timeoutMillis)
    throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException,
    MQBrokerException, UnsupportedEncodingException {
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_BROKER_CONFIG, null);

    String acturallyAddr = getActurallyBrokerAddr(addr);
    RemotingCommand response = this.remotingClient.invokeSync(acturallyAddr, request, timeoutMillis);
    assert response != null;
    switch (response.getCode()) {
        case ResponseCode.SUCCESS: {
            return MixAll.string2Properties(new String(response.getBody(), MixAll.DEFAULT_CHARSET));
        }
        default:
            break;
    }

    throw new MQBrokerException(response.getCode(), response.getRemark());
}
 
Example #20
Source File: DefaultMQPushConsumer.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Override
public MessageExt viewMessage(String topic,
    String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
    try {
        MessageDecoder.decodeMessageId(msgId);
        return this.viewMessage(msgId);
    } catch (Exception e) {
        // Ignore
    }
    return this.defaultMQPushConsumerImpl.queryMessageByUniqKey(topic, msgId);
}
 
Example #21
Source File: DefaultMQAdminExtImpl.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Override
public void updateConsumeOffset(String brokerAddr, String consumeGroup, MessageQueue mq,
    long offset) throws RemotingException, InterruptedException, MQBrokerException {
    UpdateConsumerOffsetRequestHeader requestHeader = new UpdateConsumerOffsetRequestHeader();
    requestHeader.setConsumerGroup(consumeGroup);
    requestHeader.setTopic(mq.getTopic());
    requestHeader.setQueueId(mq.getQueueId());
    requestHeader.setCommitOffset(offset);
    this.mqClientInstance.getMQClientAPIImpl().updateConsumerOffset(brokerAddr, requestHeader, timeoutMillis);
}
 
Example #22
Source File: BatchMQProducer.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
private void sendBatchMessage(List<CarreraRequest> batchRequest)
    throws MQClientException, RemotingException, InterruptedException, MQBrokerException {
    assert batchRequest.size() > 0;

    batchSendCnt.incrementAndGet();
    long startEncode = TimeUtils.getCurTime();
    Message msg = buildBatchRmqMessage(batchRequest);
    statsBatchEncodeTime.add(TimeUtils.getElapseMicros(startEncode));
    long startSend = TimeUtils.getCurTime();
    MessageQueue mq = batchRequest.get(0).getMessageQueue();
    RmqSender.send(clusterProducer.pickRocketMQProducer(), msg, mq, new SendCallback() {
        private void logResult(Throwable t, SendResult sendResult) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("sendBatchMessage:result={},topicKeys:{},batchMsgs={},batchSize={},encode.time={}ms,send.time:{}",
                    t == null ? sendResult : t,
                    batchRequest.stream().map(CarreraRequest::getKey).collect(Collectors.toList()),
                    batchRequest.size(), CollectionUtils.size(msg.getBody()),
                    TimeUtils.getElapseTime(startEncode), TimeUtils.getElapseTime(startSend));
            }
            statsBatchSendTime.add(TimeUtils.getElapseMicros(startSend));
        }

        @Override
        public void onSuccess(SendResult sendResult) {
            logResult(null, sendResult);
            batchRequest.forEach(r -> r.onSuccess(sendResult));
        }

        @Override
        public void onException(Throwable e) {
            logResult(e, null);
            batchRequest.forEach(r -> r.onException(e));
        }
    }, Constant.DEFAULT_MQ_SEND_TIMEOUT_MS);
}
 
Example #23
Source File: DefaultMQAdminExtImpl.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@Override
public void updateNameServerConfig(final Properties properties, final List<String> nameServers)
    throws InterruptedException, RemotingConnectException,
    UnsupportedEncodingException, RemotingSendRequestException, RemotingTimeoutException,
    MQClientException, MQBrokerException {
    this.mqClientInstance.getMQClientAPIImpl().updateNameServerConfig(properties, nameServers, timeoutMillis);
}
 
Example #24
Source File: MQClientAPIImpl.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public void queryMessage(
    final String addr,
    final QueryMessageRequestHeader requestHeader,
    final long timeoutMillis,
    final InvokeCallback invokeCallback,
    final Boolean isUnqiueKey
) throws RemotingException, MQBrokerException, InterruptedException {
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.QUERY_MESSAGE, requestHeader);
    request.addExtField(MixAll.UNIQUE_MSG_QUERY_FLAG, isUnqiueKey.toString());
    this.remotingClient.invokeAsync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), request, timeoutMillis,
        invokeCallback);
}
 
Example #25
Source File: MQClientAPIImpl.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
/**
 * 通过oneway的方式发送endTransaction
 * @param addr addr
 * @param requestHeader requestheader
 * @param remark remark
 * @param timeoutMillis 超时
 * @throws RemotingException ;
 * @throws MQBrokerException ;
 * @throws InterruptedException ;
 */
public void endTransactionOneway(
    final String addr,
    final EndTransactionRequestHeader requestHeader,
    final String remark,
    final long timeoutMillis
) throws RemotingException, MQBrokerException, InterruptedException {

    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.END_TRANSACTION, requestHeader);
    request.setRemark(remark);

    String acturallyAddr = getActurallyBrokerAddr(addr);
    this.remotingClient.invokeOneway(acturallyAddr, request, timeoutMillis);
}
 
Example #26
Source File: MQClientAPIImplTest.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@Test
public void testSendMessageOneWay_Success() throws RemotingException, InterruptedException, MQBrokerException {
    doNothing().when(remotingClient).invokeOneway(anyString(), any(RemotingCommand.class), anyLong());
    SendResult sendResult = mqClientAPI.sendMessage(brokerAddr, brokerName, msg, new SendMessageRequestHeader(),
        3 * 1000, CommunicationMode.ONEWAY, new SendMessageContext(), defaultMQProducerImpl);
    assertThat(sendResult).isNull();
}
 
Example #27
Source File: DefaultMQProducerImpl.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
/**
 * 带队列选择器的发送
 * @param msg msg
 * @param selector selector
 * @param arg arg
 * @param communicationMode 发送模型
 * @param sendCallback callback
 * @param timeout timeout
 * @return ;
 * @throws MQClientException ;
 * @throws RemotingException ;
 * @throws MQBrokerException ;
 * @throws InterruptedException ;
 */
private SendResult sendSelectImpl(
    Message msg,
    MessageQueueSelector selector,
    Object arg,
    final CommunicationMode communicationMode,
    final SendCallback sendCallback, final long timeout
) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {

    long beginStartTime = System.currentTimeMillis();
    this.makeSureStateOK();
    Validators.checkMessage(msg, this.defaultMQProducer);

    TopicPublishInfo topicPublishInfo = this.tryToFindTopicPublishInfo(msg.getTopic());
    if (topicPublishInfo != null && topicPublishInfo.ok()) {
        MessageQueue mq = null;
        try {
            mq = selector.select(topicPublishInfo.getMessageQueueList(), msg, arg);
        } catch (Throwable e) {
            throw new MQClientException("select message queue throwed exception.", e);
        }

        long costTime = System.currentTimeMillis() - beginStartTime;
        if (timeout < costTime) {
            throw new RemotingTooMuchRequestException("sendSelectImpl call timeout");
        }
        if (mq != null) {
            return this.sendKernelImpl(msg, mq, communicationMode, sendCallback, null, timeout - costTime);
        } else {
            throw new MQClientException("select message queue return null.", null);
        }
    }

    throw new MQClientException("No route info for this topic, " + msg.getTopic(), null);
}
 
Example #28
Source File: MQClientAPIImpl.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
private PullResult processPullResponse(
    final RemotingCommand response) throws MQBrokerException, RemotingCommandException {
    PullStatus pullStatus = PullStatus.NO_NEW_MSG;
    switch (response.getCode()) {
        case ResponseCode.SUCCESS:
            pullStatus = PullStatus.FOUND;
            break;
        case ResponseCode.PULL_NOT_FOUND:
            pullStatus = PullStatus.NO_NEW_MSG;
            break;
        case ResponseCode.PULL_RETRY_IMMEDIATELY:
            pullStatus = PullStatus.NO_MATCHED_MSG;
            break;
        case ResponseCode.PULL_OFFSET_MOVED:
            pullStatus = PullStatus.OFFSET_ILLEGAL;
            break;

        default:
            throw new MQBrokerException(response.getCode(), response.getRemark());
    }

    PullMessageResponseHeader responseHeader =
        (PullMessageResponseHeader) response.decodeCommandCustomHeader(PullMessageResponseHeader.class);

    return new PullResultExt(pullStatus, responseHeader.getNextBeginOffset(), responseHeader.getMinOffset(),
        responseHeader.getMaxOffset(), null, responseHeader.getSuggestWhichBrokerId(), response.getBody());
}
 
Example #29
Source File: DefaultMQAdminExtImpl.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public MessageExt viewMessage(String topic,
    String msgId,
    boolean isSlaveFirst) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
    try {
        MessageDecoder.decodeMessageId(msgId);
        return this.viewMessage(msgId, isSlaveFirst);
    } catch (Exception e) {
        log.warn("the msgId maybe created by new client. msgId={}", msgId, e);
    }
    return this.mqClientInstance.getMQAdminImpl().queryMessageByUniqKey(topic, msgId, isSlaveFirst);
}
 
Example #30
Source File: ResetOffsetByTimeOldCommand.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public static void resetOffset(DefaultMQAdminExt defaultMQAdminExt, String consumerGroup, String topic,
    long timestamp, boolean force,
    String timeStampStr) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
    List<RollbackStats> rollbackStatsList = defaultMQAdminExt.resetOffsetByTimestampOld(consumerGroup, topic, timestamp, force);
    System.out.printf(
        "rollback consumer offset by specified consumerGroup[%s], topic[%s], force[%s], timestamp(string)[%s], timestamp(long)[%s]%n",
        consumerGroup, topic, force, timeStampStr, timestamp);

    System.out.printf("%-20s  %-20s  %-20s  %-20s  %-20s  %-20s%n",
        "#brokerName",
        "#queueId",
        "#brokerOffset",
        "#consumerOffset",
        "#timestampOffset",
        "#rollbackOffset"
    );

    for (RollbackStats rollbackStats : rollbackStatsList) {
        System.out.printf("%-20s  %-20d  %-20d  %-20d  %-20d  %-20d%n",
            UtilAll.frontStringAtLeast(rollbackStats.getBrokerName(), 32),
            rollbackStats.getQueueId(),
            rollbackStats.getBrokerOffset(),
            rollbackStats.getConsumerOffset(),
            rollbackStats.getTimestampOffset(),
            rollbackStats.getRollbackOffset()
        );
    }
}