Java Code Examples for org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyStatus#SUCCESS

The following examples show how to use org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyStatus#SUCCESS . 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: RMQOrderListener.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs,
    ConsumeOrderlyContext context) {
    for (MessageExt msg : msgs) {
        if (isDebug) {
            if (listenerName != null && listenerName != "") {
                logger.info(listenerName + ": " + msg);
            } else {
                logger.info(msg);
            }
        }

        putMsg(msg);
        msgBodys.addData(new String(msg.getBody()));
        originMsgs.addData(msg);
    }

    return ConsumeOrderlyStatus.SUCCESS;
}
 
Example 2
Source File: RMQOrderListener.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs,
    ConsumeOrderlyContext context) {
    for (MessageExt msg : msgs) {
        if (isDebug) {
            if (listenerName != null && listenerName != "") {
                logger.info(listenerName + ": " + msg);
            } else {
                logger.info(msg);
            }
        }

        putMsg(msg);
        msgBodys.addData(new String(msg.getBody()));
        originMsgs.addData(msg);
    }

    return ConsumeOrderlyStatus.SUCCESS;
}
 
Example 3
Source File: RMQOrderListener.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs,
    ConsumeOrderlyContext context) {
    for (MessageExt msg : msgs) {
        if (isDebug) {
            if (listenerName != null && listenerName != "") {
                logger.info(listenerName + ": " + msg);
            } else {
                logger.info(msg);
            }
        }

        putMsg(msg);
        msgBodys.addData(new String(msg.getBody()));
        originMsgs.addData(msg);
    }

    return ConsumeOrderlyStatus.SUCCESS;
}
 
Example 4
Source File: DefaultRocketMQListenerContainer.java    From rocketmq-spring with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs, ConsumeOrderlyContext context) {
    for (MessageExt messageExt : msgs) {
        log.debug("received msg: {}", messageExt);
        try {
            long now = System.currentTimeMillis();
            handleMessage(messageExt);
            long costTime = System.currentTimeMillis() - now;
            log.info("consume {} cost: {} ms", messageExt.getMsgId(), costTime);
        } catch (Exception e) {
            log.warn("consume message failed. messageExt:{}", messageExt, e);
            context.setSuspendCurrentQueueTimeMillis(suspendCurrentQueueTimeMillis);
            return ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT;
        }
    }

    return ConsumeOrderlyStatus.SUCCESS;
}
 
Example 5
Source File: RMQOrderListener.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs,
    ConsumeOrderlyContext context) {
    for (MessageExt msg : msgs) {
        if (isDebug) {
            if (listnerName != null && listnerName != "") {
                logger.info(listnerName + ": " + msg);
            } else {
                logger.info(msg);
            }
        }

        putMsg(msg);
        msgBodys.addData(new String(msg.getBody()));
        originMsgs.addData(msg);
    }

    return ConsumeOrderlyStatus.SUCCESS;
}
 
Example 6
Source File: RMQOrderListener.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs,
    ConsumeOrderlyContext context) {
    for (MessageExt msg : msgs) {
        if (isDebug) {
            if (listenerName != null && listenerName != "") {
                logger.info(listenerName + ": " + msg);
            } else {
                logger.info(msg);
            }
        }

        putMsg(msg);
        msgBodys.addData(new String(msg.getBody()));
        originMsgs.addData(msg);
    }

    return ConsumeOrderlyStatus.SUCCESS;
}
 
Example 7
Source File: RocketMQListenerBindingContainer.java    From spring-cloud-alibaba with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "Duplicates" })
@Override
public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs,
		ConsumeOrderlyContext context) {
	for (MessageExt messageExt : msgs) {
		log.debug("received msg: {}", messageExt);
		try {
			long now = System.currentTimeMillis();
			rocketMQListener.onMessage(convertToSpringMessage(messageExt));
			long costTime = System.currentTimeMillis() - now;
			log.info("consume {} message key:[{}] cost: {} ms",
					messageExt.getMsgId(), messageExt.getKeys(), costTime);
		}
		catch (Exception e) {
			log.warn("consume message failed. messageExt:{}", messageExt, e);
			context.setSuspendCurrentQueueTimeMillis(
					suspendCurrentQueueTimeMillis);
			return ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT;
		}
	}

	return ConsumeOrderlyStatus.SUCCESS;
}
 
Example 8
Source File: RMQOrderListener.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs,
    ConsumeOrderlyContext context) {
    for (MessageExt msg : msgs) {
        if (isDebug) {
            if (listnerName != null && listnerName != "") {
                logger.info(listnerName + ": " + msg);
            } else {
                logger.info(msg);
            }
        }

        putMsg(msg);
        msgBodys.addData(new String(msg.getBody()));
        originMsgs.addData(msg);
    }

    return ConsumeOrderlyStatus.SUCCESS;
}
 
Example 9
Source File: RMQOrderListener.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs,
    ConsumeOrderlyContext context) {
    for (MessageExt msg : msgs) {
        if (isDebug) {
            if (listnerName != null && listnerName != "") {
                logger.info(listnerName + ": " + msg);
            } else {
                logger.info(msg);
            }
        }

        putMsg(msg);
        msgBodys.addData(new String(msg.getBody()));
        originMsgs.addData(msg);
    }

    return ConsumeOrderlyStatus.SUCCESS;
}
 
Example 10
Source File: RMQOrderListener.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Override
public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs,
                                           ConsumeOrderlyContext context) {
    for (MessageExt msg : msgs) {
        if (isDebug) {
            if (listenerName != null && listenerName != "") {
                logger.info(listenerName + ": " + msg);
            } else {
                logger.info(msg);
            }
        }

        putMsg(msg);
        msgBodys.addData(new String(msg.getBody()));
        originMsgs.addData(msg);
    }

    return ConsumeOrderlyStatus.SUCCESS;
}
 
Example 11
Source File: RocketMQDomainEventListener.java    From enode with MIT License 5 votes vote down vote up
@Override
public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs, ConsumeOrderlyContext context) {
    final CountDownLatch latch = new CountDownLatch(msgs.size());
    msgs.forEach(messageExt -> {
        QueueMessage queueMessage = RocketMQTool.covertToQueueMessage(messageExt);
        domainEventListener.handle(queueMessage, message -> {
            latch.countDown();
        });
    });
    Task.await(latch);
    return ConsumeOrderlyStatus.SUCCESS;
}
 
Example 12
Source File: RocketMQApplicationMessageListener.java    From enode with MIT License 5 votes vote down vote up
@Override
public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs, ConsumeOrderlyContext context) {
    final CountDownLatch latch = new CountDownLatch(msgs.size());
    msgs.forEach(messageExt -> {
        QueueMessage queueMessage = RocketMQTool.covertToQueueMessage(messageExt);
        applicationMessageListener.handle(queueMessage, message -> {
            latch.countDown();
        });
    });
    Task.await(latch);
    return ConsumeOrderlyStatus.SUCCESS;
}
 
Example 13
Source File: RocketMQCommandListener.java    From enode with MIT License 5 votes vote down vote up
@Override
public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs, ConsumeOrderlyContext context) {
    final CountDownLatch latch = new CountDownLatch(msgs.size());
    msgs.forEach(messageExt -> {
        QueueMessage queueMessage = RocketMQTool.covertToQueueMessage(messageExt);
        commandListener.handle(queueMessage, message -> {
            latch.countDown();
        });
    });
    Task.await(latch);
    return ConsumeOrderlyStatus.SUCCESS;
}
 
Example 14
Source File: RocketMQPublishableExceptionListener.java    From enode with MIT License 5 votes vote down vote up
@Override
public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs, ConsumeOrderlyContext context) {
    final CountDownLatch latch = new CountDownLatch(msgs.size());
    msgs.forEach(messageExt -> {
        QueueMessage queueMessage = RocketMQTool.covertToQueueMessage(messageExt);
        publishableExceptionListener.handle(queueMessage, message -> {
            latch.countDown();
        });
    });
    Task.await(latch);
    return ConsumeOrderlyStatus.SUCCESS;
}
 
Example 15
Source File: MessageListenerOrderlyImpl.java    From rocketmq-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/**
 * @param msgs    每次只取一条消息
 * @param context 封装队列和消息信息
 * @return 消费状态 成功(SUCCESS)   重试(SUSPEND_CURRENT_QUEUE_A_MOMENT)
 */
@Override
public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs, ConsumeOrderlyContext context) {
    ConsumeStatus status = MessageHandler.handleMessage(listener, msgs, context.getMessageQueue());
    if (status.equals(ConsumeStatus.SUCCESS)) {
        return ConsumeOrderlyStatus.SUCCESS;
    } else {
        return ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT;
    }
}
 
Example 16
Source File: AbstractMQPushConsumer.java    From rocketmq-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/**
 * 原生dealMessage方法,可以重写此方法自定义序列化和返回消费成功的相关逻辑
 *
 * @param list 消息列表
 * @param consumeOrderlyContext 上下文
 * @return 处理结果
 */
public ConsumeOrderlyStatus dealMessage(List<MessageExt> list, ConsumeOrderlyContext consumeOrderlyContext) {
    for(MessageExt messageExt : list) {
        log.info("receive msgId: {}, tags : {}" , messageExt.getMsgId(), messageExt.getTags());
        T t = parseMessage(messageExt);
        Map<String, Object> ext = parseExtParam(messageExt);
        if( null != t && !process(t, ext)) {
            log.warn("consume fail , ask for re-consume , msgId: {}", messageExt.getMsgId());
            return ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT;
        }
    }
    return  ConsumeOrderlyStatus.SUCCESS;
}