Search in sources :

Example 51 with MQClientException

use of org.apache.rocketmq.client.exception.MQClientException in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class DefaultMQPullConsumerImpl method copySubscription.

private void copySubscription() throws MQClientException {
    try {
        Set<String> registerTopics = this.defaultMQPullConsumer.getRegisterTopics();
        if (registerTopics != null) {
            for (final String topic : registerTopics) {
                SubscriptionData subscriptionData = // 
                FilterAPI.buildSubscriptionData(// 
                this.defaultMQPullConsumer.getConsumerGroup(), topic, SubscriptionData.SUB_ALL);
                this.rebalanceImpl.getSubscriptionInner().put(topic, subscriptionData);
            }
        }
    } catch (Exception e) {
        throw new MQClientException("subscription exception", e);
    }
}
Also used : SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData) MQClientException(org.apache.rocketmq.client.exception.MQClientException) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) RemotingException(org.apache.rocketmq.remoting.exception.RemotingException) MQClientException(org.apache.rocketmq.client.exception.MQClientException)

Example 52 with MQClientException

use of org.apache.rocketmq.client.exception.MQClientException in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class DefaultMQPushConsumerImpl method sendMessageBack.

// 失败消息发broker
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());
        this.mQClientFactory.getMQClientAPIImpl().consumerSendMessageBack(brokerAddr, msg, this.defaultMQPushConsumer.getConsumerGroup(), delayLevel, 5000, getMaxReconsumeTimes());
    } catch (Exception e) {
        log.error("sendMessageBack Exception, " + this.defaultMQPushConsumer.getConsumerGroup(), e);
        Message newMsg = 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());
        MessageAccessor.setReconsumeTime(newMsg, String.valueOf(msg.getReconsumeTimes() + 1));
        MessageAccessor.setMaxReconsumeTimes(newMsg, String.valueOf(getMaxReconsumeTimes()));
        newMsg.setDelayTimeLevel(3 + msg.getReconsumeTimes());
        this.mQClientFactory.getDefaultMQProducer().send(newMsg);
    }
}
Also used : Message(org.apache.rocketmq.common.message.Message) MQClientException(org.apache.rocketmq.client.exception.MQClientException) RemotingException(org.apache.rocketmq.remoting.exception.RemotingException) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException)

Example 53 with MQClientException

use of org.apache.rocketmq.client.exception.MQClientException in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class DefaultMQPushConsumerImpl method checkConfig.

private void checkConfig() throws MQClientException {
    Validators.checkGroup(this.defaultMQPushConsumer.getConsumerGroup());
    if (null == this.defaultMQPushConsumer.getConsumerGroup()) {
        throw new MQClientException("consumerGroup is null" + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), null);
    }
    if (this.defaultMQPushConsumer.getConsumerGroup().equals(MixAll.DEFAULT_CONSUMER_GROUP)) {
        throw new MQClientException("consumerGroup can not equal " + MixAll.DEFAULT_CONSUMER_GROUP + ", please specify another one." + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), null);
    }
    if (null == this.defaultMQPushConsumer.getMessageModel()) {
        throw new MQClientException("messageModel is null" + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), null);
    }
    if (null == this.defaultMQPushConsumer.getConsumeFromWhere()) {
        throw new MQClientException("consumeFromWhere is null" + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), null);
    }
    Date dt = UtilAll.parseDate(this.defaultMQPushConsumer.getConsumeTimestamp(), UtilAll.YYYYMMDDHHMMSS);
    if (null == dt) {
        throw new MQClientException("consumeTimestamp is invalid, the valid format is yyyyMMddHHmmss,but received " + this.defaultMQPushConsumer.getConsumeTimestamp() + " " + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), null);
    }
    // allocateMessageQueueStrategy
    if (null == this.defaultMQPushConsumer.getAllocateMessageQueueStrategy()) {
        throw new MQClientException("allocateMessageQueueStrategy is null" + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), null);
    }
    // subscription
    if (null == this.defaultMQPushConsumer.getSubscription()) {
        throw new MQClientException("subscription is null" + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), null);
    }
    // messageListener
    if (null == this.defaultMQPushConsumer.getMessageListener()) {
        throw new MQClientException("messageListener is null" + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), null);
    }
    boolean orderly = this.defaultMQPushConsumer.getMessageListener() instanceof MessageListenerOrderly;
    boolean concurrently = this.defaultMQPushConsumer.getMessageListener() instanceof MessageListenerConcurrently;
    if (!orderly && !concurrently) {
        throw new MQClientException("messageListener must be instanceof MessageListenerOrderly or MessageListenerConcurrently" + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), null);
    }
    // consumeThreadMin
    if (this.defaultMQPushConsumer.getConsumeThreadMin() < 1 || this.defaultMQPushConsumer.getConsumeThreadMin() > 1000 || this.defaultMQPushConsumer.getConsumeThreadMin() > this.defaultMQPushConsumer.getConsumeThreadMax()) {
        throw new MQClientException("consumeThreadMin Out of range [1, 1000]" + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), null);
    }
    // consumeThreadMax
    if (this.defaultMQPushConsumer.getConsumeThreadMax() < 1 || this.defaultMQPushConsumer.getConsumeThreadMax() > 1000) {
        throw new MQClientException("consumeThreadMax Out of range [1, 1000]" + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), null);
    }
    // consumeConcurrentlyMaxSpan
    if (this.defaultMQPushConsumer.getConsumeConcurrentlyMaxSpan() < 1 || this.defaultMQPushConsumer.getConsumeConcurrentlyMaxSpan() > 65535) {
        throw new MQClientException("consumeConcurrentlyMaxSpan Out of range [1, 65535]" + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), null);
    }
    // pullThresholdForQueue
    if (this.defaultMQPushConsumer.getPullThresholdForQueue() < 1 || this.defaultMQPushConsumer.getPullThresholdForQueue() > 65535) {
        throw new MQClientException("pullThresholdForQueue Out of range [1, 65535]" + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), null);
    }
    // pullInterval
    if (this.defaultMQPushConsumer.getPullInterval() < 0 || this.defaultMQPushConsumer.getPullInterval() > 65535) {
        throw new MQClientException("pullInterval Out of range [0, 65535]" + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), null);
    }
    // consumeMessageBatchMaxSize
    if (this.defaultMQPushConsumer.getConsumeMessageBatchMaxSize() < 1 || this.defaultMQPushConsumer.getConsumeMessageBatchMaxSize() > 1024) {
        throw new MQClientException("consumeMessageBatchMaxSize Out of range [1, 1024]" + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), null);
    }
    // pullBatchSize
    if (this.defaultMQPushConsumer.getPullBatchSize() < 1 || this.defaultMQPushConsumer.getPullBatchSize() > 1024) {
        throw new MQClientException("pullBatchSize Out of range [1, 1024]" + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), null);
    }
}
Also used : MessageListenerConcurrently(org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently) MessageListenerOrderly(org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly) MQClientException(org.apache.rocketmq.client.exception.MQClientException) Date(java.util.Date)

Example 54 with MQClientException

use of org.apache.rocketmq.client.exception.MQClientException in project ignite by apache.

the class RocketMQStreamer method start.

/**
 * Starts streamer.
 *
 * @throws IgniteException If failed.
 */
public void start() {
    if (!stopped)
        throw new IgniteException("Attempted to start an already started RocketMQ streamer");
    // validate parameters.
    A.notNull(getStreamer(), "streamer");
    A.notNull(getIgnite(), "ignite");
    A.notNull(topic, "topic");
    A.notNull(consumerGrp, "consumer group");
    A.notNullOrEmpty(nameSrvAddr, "nameserver address");
    A.ensure(null != getMultipleTupleExtractor(), "Multiple tuple extractor must be configured");
    log = getIgnite().log();
    consumer = new DefaultMQPushConsumer(consumerGrp);
    consumer.setNamesrvAddr(nameSrvAddr);
    consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET);
    try {
        consumer.subscribe(topic, "*");
    } catch (MQClientException e) {
        throw new IgniteException("Failed to subscribe to " + topic, e);
    }
    consumer.registerMessageListener(this);
    try {
        consumer.start();
    } catch (MQClientException e) {
        throw new IgniteException("Failed to start the streamer", e);
    }
    stopped = false;
}
Also used : IgniteException(org.apache.ignite.IgniteException) DefaultMQPushConsumer(org.apache.rocketmq.client.consumer.DefaultMQPushConsumer) MQClientException(org.apache.rocketmq.client.exception.MQClientException)

Example 55 with MQClientException

use of org.apache.rocketmq.client.exception.MQClientException in project rocketmq-externals by apache.

the class ConsumerServiceImpl method resetOffset.

@Override
@MultiMQAdminCmdMethod
public Map<String, ConsumerGroupRollBackStat> resetOffset(ResetOffsetRequest resetOffsetRequest) {
    Map<String, ConsumerGroupRollBackStat> groupRollbackStats = Maps.newHashMap();
    for (String consumerGroup : resetOffsetRequest.getConsumerGroupList()) {
        try {
            Map<MessageQueue, Long> rollbackStatsMap = mqAdminExt.resetOffsetByTimestamp(resetOffsetRequest.getTopic(), consumerGroup, resetOffsetRequest.getResetTime(), resetOffsetRequest.isForce());
            ConsumerGroupRollBackStat consumerGroupRollBackStat = new ConsumerGroupRollBackStat(true);
            List<RollbackStats> rollbackStatsList = consumerGroupRollBackStat.getRollbackStatsList();
            for (Map.Entry<MessageQueue, Long> rollbackStatsEntty : rollbackStatsMap.entrySet()) {
                RollbackStats rollbackStats = new RollbackStats();
                rollbackStats.setRollbackOffset(rollbackStatsEntty.getValue());
                rollbackStats.setQueueId(rollbackStatsEntty.getKey().getQueueId());
                rollbackStats.setBrokerName(rollbackStatsEntty.getKey().getBrokerName());
                rollbackStatsList.add(rollbackStats);
            }
            groupRollbackStats.put(consumerGroup, consumerGroupRollBackStat);
        } catch (MQClientException e) {
            if (ResponseCode.CONSUMER_NOT_ONLINE == e.getResponseCode()) {
                try {
                    ConsumerGroupRollBackStat consumerGroupRollBackStat = new ConsumerGroupRollBackStat(true);
                    List<RollbackStats> rollbackStatsList = mqAdminExt.resetOffsetByTimestampOld(consumerGroup, resetOffsetRequest.getTopic(), resetOffsetRequest.getResetTime(), true);
                    consumerGroupRollBackStat.setRollbackStatsList(rollbackStatsList);
                    groupRollbackStats.put(consumerGroup, consumerGroupRollBackStat);
                    continue;
                } catch (Exception err) {
                    logger.error("op=resetOffset_which_not_online_error", err);
                }
            } else {
                logger.error("op=resetOffset_error", e);
            }
            groupRollbackStats.put(consumerGroup, new ConsumerGroupRollBackStat(false, e.getMessage()));
        } catch (Exception e) {
            logger.error("op=resetOffset_error", e);
            groupRollbackStats.put(consumerGroup, new ConsumerGroupRollBackStat(false, e.getMessage()));
        }
    }
    return groupRollbackStats;
}
Also used : ConsumerGroupRollBackStat(org.apache.rocketmq.console.model.ConsumerGroupRollBackStat) MQClientException(org.apache.rocketmq.client.exception.MQClientException) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) RollbackStats(org.apache.rocketmq.common.admin.RollbackStats) GroupList(org.apache.rocketmq.common.protocol.body.GroupList) List(java.util.List) Map(java.util.Map) MQClientException(org.apache.rocketmq.client.exception.MQClientException) MultiMQAdminCmdMethod(org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod)

Aggregations

MQClientException (org.apache.rocketmq.client.exception.MQClientException)230 MQBrokerException (org.apache.rocketmq.client.exception.MQBrokerException)70 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)69 RemotingException (org.apache.rocketmq.remoting.exception.RemotingException)65 Message (org.apache.rocketmq.common.message.Message)35 SendResult (org.apache.rocketmq.client.producer.SendResult)34 DefaultMQProducer (org.apache.rocketmq.client.producer.DefaultMQProducer)29 MessageExt (org.apache.rocketmq.common.message.MessageExt)25 UnsupportedEncodingException (java.io.UnsupportedEncodingException)18 SubscriptionData (org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData)18 DefaultMQPushConsumer (org.apache.rocketmq.client.consumer.DefaultMQPushConsumer)17 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)17 RemotingCommandException (org.apache.rocketmq.remoting.exception.RemotingCommandException)17 PullResult (org.apache.rocketmq.client.consumer.PullResult)16 TopicList (org.apache.rocketmq.common.protocol.body.TopicList)16 MessageListenerConcurrently (org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently)15 TopicRouteData (org.apache.rocketmq.common.protocol.route.TopicRouteData)15 BrokerData (org.apache.rocketmq.common.protocol.route.BrokerData)14 ConsumeConcurrentlyContext (org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext)11 ConsumeConcurrentlyStatus (org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus)11