com.alibaba.rocketmq.remoting.exception.RemotingException Java Examples

The following examples show how to use com.alibaba.rocketmq.remoting.exception.RemotingException. 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: DefaultMQProducerImpl.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 6 votes vote down vote up
public void send(Message msg, MessageQueue mq, SendCallback sendCallback, long timeout)
        throws MQClientException, RemotingException, InterruptedException {
    this.makeSureStateOK();
    Validators.checkMessage(msg, this.defaultMQProducer);

    if (!msg.getTopic().equals(mq.getTopic())) {
        throw new MQClientException("message's topic not equal mq's topic", null);
    }

    try {
        this.sendKernelImpl(msg, mq, CommunicationMode.ASYNC, sendCallback, timeout);
    }
    catch (MQBrokerException e) {
        throw new MQClientException("unknow exception", e);
    }
}
 
Example #2
Source File: MonitorService.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public void reportConsumerRunningInfo(final String consumerGroup) throws InterruptedException,
        MQBrokerException, RemotingException, MQClientException {
    ConsumerConnection cc = defaultMQAdminExt.examineConsumerConnectionInfo(consumerGroup);
    TreeMap<String, ConsumerRunningInfo> infoMap = new TreeMap<String, ConsumerRunningInfo>();
    for (Connection c : cc.getConnectionSet()) {
        String clientId = c.getClientId();

        if (c.getVersion() < MQVersion.Version.V3_1_8_SNAPSHOT.ordinal()) {
            continue;
        }

        try {
            ConsumerRunningInfo info =
                    defaultMQAdminExt.getConsumerRunningInfo(consumerGroup, clientId, false);
            infoMap.put(clientId, info);
        } catch (Exception e) {
        }
    }

    if (!infoMap.isEmpty()) {
        this.monitorListener.reportConsumerRunningInfo(infoMap);
    }
}
 
Example #3
Source File: RemoteBrokerOffsetStore.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Update the Consumer Offset, once the Master is off, updated to Slave,
 * here need to be optimized.
 */
private void updateConsumeOffsetToBroker(MessageQueue mq, long offset) 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) {
        UpdateConsumerOffsetRequestHeader requestHeader = new UpdateConsumerOffsetRequestHeader();
        requestHeader.setTopic(mq.getTopic());
        requestHeader.setConsumerGroup(this.groupName);
        requestHeader.setQueueId(mq.getQueueId());
        requestHeader.setCommitOffset(offset);

        this.mQClientFactory.getMQClientAPIImpl().updateConsumerOffsetOneway(
                findBrokerResult.getBrokerAddr(), requestHeader, 1000 * 5);
    } else {
        throw new MQClientException("The broker[" + mq.getBrokerName() + "] not exist", null);
    }
}
 
Example #4
Source File: ProducerServiceImpl.java    From rocket-console with Apache License 2.0 5 votes vote down vote up
@Override
public ProducerConnection getProducerConnection(String producerGroup, String topic) {
    try {
        return mqAdminExt.examineProducerConnectionInfo(producerGroup, topic);
    } catch (RemotingException | MQClientException | MQBrokerException | InterruptedException e) {
        throw Throwables.propagate(e);
    }
}
 
Example #5
Source File: DefaultMQPullConsumerImpl.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
public void sendMessageBack(MessageExt msg, int delayLevel, final String brokerName, String consumerGroup)
        throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
    try {
        String brokerAddr =
                (null != brokerName) ? this.mQClientFactory.findBrokerAddressInPublish(brokerName)
                        : RemotingHelper.parseSocketAddressAddr(msg.getStoreHost());

        if (UtilAll.isBlank(consumerGroup)) {
            consumerGroup = this.defaultMQPullConsumer.getConsumerGroup();
        }

        this.mQClientFactory.getMQClientAPIImpl().consumerSendMessageBack(brokerAddr, msg, consumerGroup,
                delayLevel, 3000);
    } catch (Exception e) {
        log.error("sendMessageBack Exception, " + this.defaultMQPullConsumer.getConsumerGroup(), e);

        Message newMsg =
                new Message(MixAll.getRetryTopic(this.defaultMQPullConsumer.getConsumerGroup()),
                        msg.getBody());

        newMsg.setFlag(msg.getFlag());
        MessageAccessor.setProperties(newMsg, msg.getProperties());
        MessageAccessor.putProperty(newMsg, MessageConst.PROPERTY_RETRY_TOPIC, msg.getTopic());

        this.mQClientFactory.getDefaultMQProducer().send(newMsg);
    }
}
 
Example #6
Source File: DefaultMQPushConsumerImpl.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
public List<QueueTimeSpan> queryConsumeTimeSpan(final String topic) throws RemotingException,
        MQClientException, InterruptedException, MQBrokerException {
    List<QueueTimeSpan> queueTimeSpan = new ArrayList<QueueTimeSpan>();
    TopicRouteData routeData =
            this.mQClientFactory.getMQClientAPIImpl().getTopicRouteInfoFromNameServer(topic, 3000);
    for (BrokerData brokerData : routeData.getBrokerDatas()) {
        String addr = brokerData.selectBrokerAddr();
        queueTimeSpan.addAll(this.mQClientFactory.getMQClientAPIImpl().queryConsumeTimeSpan(addr, topic,
                groupName(), 3000l));
    }

    return queueTimeSpan;
}
 
Example #7
Source File: DefaultMQPushConsumer.java    From rocketmq 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) {
    }
    return this.defaultMQPushConsumerImpl.queryMessageByUniqKey(topic, msgId);
}
 
Example #8
Source File: DefaultMQPushConsumerImpl.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public void resetOffsetByTimeStamp(long timeStamp)
        throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
    for (String topic : rebalanceImpl.getSubscriptionInner().keySet()) {
        Set<MessageQueue> mqs = rebalanceImpl.getTopicSubscribeInfoTable().get(topic);
        Map<MessageQueue, Long> offsetTable = new HashMap<MessageQueue, Long>();
        if (mqs != null) {
            for (MessageQueue mq : mqs) {
                long offset = searchOffset(mq, timeStamp);
                offsetTable.put(mq, offset);
            }
            this.mQClientFactory.resetOffset(topic, groupName(), offsetTable);
        }
    }
}
 
Example #9
Source File: DefaultMQProducerImpl.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
/**
 * SELECT ONEWAY -------------------------------------------------------
 */
public void sendOneway(Message msg, MessageQueueSelector selector, Object arg)
        throws MQClientException, RemotingException, InterruptedException {
    try {
        this.sendSelectImpl(msg, selector, arg, CommunicationMode.ONEWAY, null, this.defaultMQProducer.getSendMsgTimeout());
    } catch (MQBrokerException e) {
        throw new MQClientException("unknow exception", e);
    }
}
 
Example #10
Source File: DefaultMQPushConsumerImpl.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
public void sendMessageBack(MessageExt msg, int delayLevel, final String brokerName)
        throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
    try {
        String brokerAddr =
                (null != brokerName) ? this.mQClientFactory.findBrokerAddressInPublish(brokerName)
                        : RemotingHelper.parseSocketAddressAddr(msg.getStoreHost());
        //结合结合SendMessageProcessor.consumerSendMsgBack阅读
        //消费失败,重新打回消息到broker中   这里发送的报文的code:CONSUMER_SEND_MSG_BACK,对端收到后,会创建重试队列RETRY_GROUP_TOPIC_PREFIX + consumer
        this.mQClientFactory.getMQClientAPIImpl().consumerSendMessageBack(brokerAddr, msg,
            this.defaultMQPushConsumer.getConsumerGroup(), delayLevel, 5000);
    }

    catch (Exception e) { //消费失败的消息打回重试队列失败,,需要重新发送到重试队列
        log.error("sendMessageBack Exception, " + this.defaultMQPushConsumer.getConsumerGroup(), e);

        //这里发送的报文code默认为code:SEND_MESSAGE,因此需要带上重试队列名,对于broker来说就相当于收到了一条发往RETRY_GROUP_TOPIC_PREFIX + consumer的消息
        Message newMsg =
                //修改topic,修改后的topic为 RETRY_GROUP_TOPIC_PREFIX + consumer  需要重新发送
                new Message(MixAll.getRetryTopic(this.defaultMQPushConsumer.getConsumerGroup()),
                    msg.getBody());

        String originMsgId = MessageAccessor.getOriginMessageId(msg);
        MessageAccessor.setOriginMessageId(newMsg, UtilAll.isBlank(originMsgId) ? msg.getMsgId()
                : originMsgId);

        newMsg.setFlag(msg.getFlag());
        MessageAccessor.setProperties(newMsg, msg.getProperties());
        MessageAccessor.putProperty(newMsg, MessageConst.PROPERTY_RETRY_TOPIC, msg.getTopic());
        int reTimes = msg.getReconsumeTimes() + 1;
        MessageAccessor.setReconsumeTime(newMsg, reTimes + "");
        newMsg.setDelayTimeLevel(3 + reTimes);

        this.mQClientFactory.getDefaultMQProducer().send(newMsg);
    }
}
 
Example #11
Source File: ResetOffsetByTimeOldCommand.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.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() //
            );
    }
}
 
Example #12
Source File: DefaultMQProducer.java    From rocketmq 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 {
        MessageId oldMsgId = MessageDecoder.decodeMessageId(msgId);
        return this.viewMessage(msgId);
    } catch (Exception e) {
    }
    return this.defaultMQProducerImpl.queryMessageByUniqKey(topic, msgId);
}
 
Example #13
Source File: DefaultMQProducerImpl.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
private SendResult sendSelectImpl(//
                                  Message msg, //
                                  MessageQueueSelector selector, //
                                  Object arg, //
                                  final CommunicationMode communicationMode, //
                                  final SendCallback sendCallback, final long timeout//
) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
    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);
        }

        if (mq != null) {
            return this.sendKernelImpl(msg, mq, communicationMode, sendCallback, null, timeout);
        } else {
            throw new MQClientException("select message queue return null.", null);
        }
    }

    throw new MQClientException("No route info for this topic, " + msg.getTopic(), null);
}
 
Example #14
Source File: DefaultMQProducerImpl.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
public void send(Message msg, MessageQueueSelector selector, Object arg, SendCallback sendCallback,
        long timeout) throws MQClientException, RemotingException, InterruptedException {
    try {
        this.sendSelectImpl(msg, selector, arg, CommunicationMode.ASYNC, sendCallback, timeout);
    }
    catch (MQBrokerException e) {
        throw new MQClientException("unknown exception", e);
    }
}
 
Example #15
Source File: TopicController.java    From rocket-console with Apache License 2.0 4 votes vote down vote up
@RequestMapping(value = "/list.query", method = RequestMethod.GET)
@JsonBody
public Object list() throws MQClientException, RemotingException, InterruptedException {
    return topicService.fetchAllTopicList();
}
 
Example #16
Source File: DefaultMQPushConsumer.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void sendMessageBack(MessageExt msg, int delayLevel) throws RemotingException, MQBrokerException, InterruptedException,
        MQClientException {
    this.defaultMQPushConsumerImpl.sendMessageBack(msg, delayLevel, null);
}
 
Example #17
Source File: MQProducer.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
SendResult send(final Message msg, final MessageQueueSelector selector, final Object arg)
throws MQClientException, RemotingException, MQBrokerException, InterruptedException;
 
Example #18
Source File: DefaultMQProducer.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
@Override
public SendResult send(Message msg, long timeout) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
    return this.defaultMQProducerImpl.send(msg, timeout);
}
 
Example #19
Source File: PullAPIWrapper.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public PullResult pullKernelImpl(//
                                 final MessageQueue mq,// 1
                                 final String subExpression,// 2
                                 final long subVersion,// 3
                                 final long offset,// 4
                                 final int maxNums,// 5
                                 final int sysFlag,// 6
                                 final long commitOffset,// 7
                                 final long brokerSuspendMaxTimeMillis,// 8
                                 final long timeoutMillis,// 9
                                 final CommunicationMode communicationMode,// 10
                                 final PullCallback pullCallback// 11
) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
    FindBrokerResult findBrokerResult =
            this.mQClientFactory.findBrokerAddressInSubscribe(mq.getBrokerName(),
                    this.recalculatePullFromWhichNode(mq), false);
    if (null == findBrokerResult) {
        this.mQClientFactory.updateTopicRouteInfoFromNameServer(mq.getTopic());
        findBrokerResult =
                this.mQClientFactory.findBrokerAddressInSubscribe(mq.getBrokerName(),
                        this.recalculatePullFromWhichNode(mq), false);
    }

    if (findBrokerResult != null) {
        int sysFlagInner = sysFlag;

        if (findBrokerResult.isSlave()) {
            sysFlagInner = PullSysFlag.clearCommitOffsetFlag(sysFlagInner);
        }

        PullMessageRequestHeader requestHeader = new PullMessageRequestHeader();
        requestHeader.setConsumerGroup(this.consumerGroup);
        requestHeader.setTopic(mq.getTopic());
        requestHeader.setQueueId(mq.getQueueId());
        requestHeader.setQueueOffset(offset);
        requestHeader.setMaxMsgNums(maxNums);
        requestHeader.setSysFlag(sysFlagInner);
        requestHeader.setCommitOffset(commitOffset);
        requestHeader.setSuspendTimeoutMillis(brokerSuspendMaxTimeMillis);
        requestHeader.setSubscription(subExpression);
        requestHeader.setSubVersion(subVersion);

        String brokerAddr = findBrokerResult.getBrokerAddr();
        if (PullSysFlag.hasClassFilterFlag(sysFlagInner)) {
            brokerAddr = computPullFromWhichFilterServer(mq.getTopic(), brokerAddr);
        }

        PullResult pullResult = this.mQClientFactory.getMQClientAPIImpl().pullMessage(//
                brokerAddr,//
                requestHeader,//
                timeoutMillis,//
                communicationMode,//
                pullCallback);

        return pullResult;
    }

    throw new MQClientException("The broker[" + mq.getBrokerName() + "] not exist", null);
}
 
Example #20
Source File: MQProducer.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
void send(final Message msg, final MessageQueue mq, final SendCallback sendCallback)
throws MQClientException, RemotingException, InterruptedException;
 
Example #21
Source File: DefaultMQProducerImpl.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
public SendResult send(Message msg, long timeout) throws MQClientException, RemotingException,
        MQBrokerException, InterruptedException {
    return this.sendDefaultImpl(msg, CommunicationMode.SYNC, null, timeout);
}
 
Example #22
Source File: MQProducer.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
void send(final Message msg, final MessageQueueSelector selector, final Object arg,
  final SendCallback sendCallback) throws MQClientException, RemotingException,
InterruptedException;
 
Example #23
Source File: DefaultMQPushConsumer.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public MessageExt viewMessage(String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
    return this.defaultMQPushConsumerImpl.viewMessage(msgId);
}
 
Example #24
Source File: MQAdminExtImpl.java    From rocket-console with Apache License 2.0 4 votes vote down vote up
@Override
public void deleteKvConfig(String namespace, String key)
        throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
    MQAdminInstance.threadLocalMQAdminExt().deleteKvConfig(namespace, key);
}
 
Example #25
Source File: MQProducer.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
void sendOneway(final Message msg) throws MQClientException, RemotingException,
InterruptedException;
 
Example #26
Source File: DefaultMQPullConsumerImpl.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public PullResult pullBlockIfNotFound(MessageQueue mq, String subExpression, long offset, int maxNums)
        throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
    return this.pullSyncImpl(mq, subExpression, offset, maxNums, true, this.getDefaultMQPullConsumer().getConsumerPullTimeoutMillis());
}
 
Example #27
Source File: MQAdminExtImpl.java    From rocket-console with Apache License 2.0 4 votes vote down vote up
@Override
public ConsumeMessageDirectlyResult consumeMessageDirectly(String consumerGroup, String clientId, String topic, String msgId) throws RemotingException, MQClientException, InterruptedException, MQBrokerException {
    return  MQAdminInstance.threadLocalMQAdminExt().consumeMessageDirectly(consumerGroup,clientId,topic,msgId);
}
 
Example #28
Source File: DefaultMQPullConsumerImpl.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
public void pullBlockIfNotFound(MessageQueue mq, String subExpression, long offset, int maxNums,
                                PullCallback pullCallback) throws MQClientException, RemotingException, InterruptedException {
    this.pullAsyncImpl(mq, subExpression, offset, maxNums, pullCallback, true, this
            .getDefaultMQPullConsumer().getConsumerPullTimeoutMillis());
}
 
Example #29
Source File: DefaultMQPullConsumer.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void sendMessageBack(MessageExt msg, int delayLevel, String brokerName, String consumerGroup)
        throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
    this.defaultMQPullConsumerImpl.sendMessageBack(msg, delayLevel, brokerName, consumerGroup);
}
 
Example #30
Source File: DefaultMQPullConsumer.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void sendMessageBack(MessageExt msg, int delayLevel) throws RemotingException, MQBrokerException,
        InterruptedException, MQClientException {
    this.defaultMQPullConsumerImpl.sendMessageBack(msg, delayLevel, null);
}