Search in sources :

Example 11 with ConsumeMessageDirectlyResult

use of org.apache.rocketmq.common.protocol.body.ConsumeMessageDirectlyResult in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class QueryMsgByIdSubCommand method pushMsg.

private void pushMsg(final DefaultMQAdminExt defaultMQAdminExt, final String consumerGroup, final String clientId, final String msgId) {
    try {
        ConsumeMessageDirectlyResult result = defaultMQAdminExt.consumeMessageDirectly(consumerGroup, clientId, msgId);
        System.out.printf("%s", result);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ConsumeMessageDirectlyResult(org.apache.rocketmq.common.protocol.body.ConsumeMessageDirectlyResult) IOException(java.io.IOException) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) MQClientException(org.apache.rocketmq.client.exception.MQClientException) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) RemotingException(org.apache.rocketmq.remoting.exception.RemotingException)

Example 12 with ConsumeMessageDirectlyResult

use of org.apache.rocketmq.common.protocol.body.ConsumeMessageDirectlyResult in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class QueryMsgByUniqueKeySubCommand method execute.

@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    try {
        defaultMQAdminExt.start();
        final String msgId = commandLine.getOptionValue('i').trim();
        final String topic = commandLine.getOptionValue('t').trim();
        if (commandLine.hasOption('g') && commandLine.hasOption('d')) {
            final String consumerGroup = commandLine.getOptionValue('g').trim();
            final String clientId = commandLine.getOptionValue('d').trim();
            ConsumeMessageDirectlyResult result = defaultMQAdminExt.consumeMessageDirectly(consumerGroup, clientId, topic, msgId);
            System.out.printf("%s", result);
        } else {
            queryById(defaultMQAdminExt, topic, msgId);
        }
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
Also used : ConsumeMessageDirectlyResult(org.apache.rocketmq.common.protocol.body.ConsumeMessageDirectlyResult) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) IOException(java.io.IOException) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) MQClientException(org.apache.rocketmq.client.exception.MQClientException) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) RemotingException(org.apache.rocketmq.remoting.exception.RemotingException)

Example 13 with ConsumeMessageDirectlyResult

use of org.apache.rocketmq.common.protocol.body.ConsumeMessageDirectlyResult in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class ClientRemotingProcessor method consumeMessageDirectly.

private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    final ConsumeMessageDirectlyResultRequestHeader requestHeader = (ConsumeMessageDirectlyResultRequestHeader) request.decodeCommandCustomHeader(ConsumeMessageDirectlyResultRequestHeader.class);
    final MessageExt msg = MessageDecoder.decode(ByteBuffer.wrap(request.getBody()));
    ConsumeMessageDirectlyResult result = this.mqClientFactory.consumeMessageDirectly(msg, requestHeader.getConsumerGroup(), requestHeader.getBrokerName());
    if (null != result) {
        response.setCode(ResponseCode.SUCCESS);
        response.setBody(result.encode());
    } else {
        response.setCode(ResponseCode.SYSTEM_ERROR);
        response.setRemark(String.format("The Consumer Group <%s> not exist in this consumer", requestHeader.getConsumerGroup()));
    }
    return response;
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) MessageExt(org.apache.rocketmq.common.message.MessageExt) ConsumeMessageDirectlyResult(org.apache.rocketmq.common.protocol.body.ConsumeMessageDirectlyResult) ConsumeMessageDirectlyResultRequestHeader(org.apache.rocketmq.common.protocol.header.ConsumeMessageDirectlyResultRequestHeader)

Example 14 with ConsumeMessageDirectlyResult

use of org.apache.rocketmq.common.protocol.body.ConsumeMessageDirectlyResult in project rocketmq by apache.

the class QueryMsgByIdSubCommand method pushMsg.

private void pushMsg(final DefaultMQAdminExt defaultMQAdminExt, final String consumerGroup, final String clientId, final String msgId) {
    try {
        ConsumeMessageDirectlyResult result = defaultMQAdminExt.consumeMessageDirectly(consumerGroup, clientId, msgId);
        System.out.printf("%s", result);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ConsumeMessageDirectlyResult(org.apache.rocketmq.common.protocol.body.ConsumeMessageDirectlyResult) IOException(java.io.IOException) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) MQClientException(org.apache.rocketmq.client.exception.MQClientException) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) RemotingException(org.apache.rocketmq.remoting.exception.RemotingException)

Example 15 with ConsumeMessageDirectlyResult

use of org.apache.rocketmq.common.protocol.body.ConsumeMessageDirectlyResult in project rocketmq by apache.

the class ConsumeMessageConcurrentlyService method consumeMessageDirectly.

@Override
public ConsumeMessageDirectlyResult consumeMessageDirectly(MessageExt msg, String brokerName) {
    ConsumeMessageDirectlyResult result = new ConsumeMessageDirectlyResult();
    result.setOrder(false);
    result.setAutoCommit(true);
    List<MessageExt> msgs = new ArrayList<MessageExt>();
    msgs.add(msg);
    MessageQueue mq = new MessageQueue();
    mq.setBrokerName(brokerName);
    mq.setTopic(msg.getTopic());
    mq.setQueueId(msg.getQueueId());
    ConsumeConcurrentlyContext context = new ConsumeConcurrentlyContext(mq);
    this.resetRetryTopic(msgs);
    final long beginTime = System.currentTimeMillis();
    log.info("consumeMessageDirectly receive new message: {}", msg);
    try {
        ConsumeConcurrentlyStatus status = this.messageListener.consumeMessage(msgs, context);
        if (status != null) {
            switch(status) {
                case CONSUME_SUCCESS:
                    result.setConsumeResult(CMResult.CR_SUCCESS);
                    break;
                case RECONSUME_LATER:
                    result.setConsumeResult(CMResult.CR_LATER);
                    break;
                default:
                    break;
            }
        } else {
            result.setConsumeResult(CMResult.CR_RETURN_NULL);
        }
    } catch (Throwable e) {
        result.setConsumeResult(CMResult.CR_THROW_EXCEPTION);
        result.setRemark(RemotingHelper.exceptionSimpleDesc(e));
        log.warn(String.format("consumeMessageDirectly exception: %s Group: %s Msgs: %s MQ: %s", RemotingHelper.exceptionSimpleDesc(e), ConsumeMessageConcurrentlyService.this.consumerGroup, msgs, mq), e);
    }
    result.setSpentTimeMills(System.currentTimeMillis() - beginTime);
    log.info("consumeMessageDirectly Result: {}", result);
    return result;
}
Also used : ConsumeConcurrentlyContext(org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext) MessageExt(org.apache.rocketmq.common.message.MessageExt) ConsumeMessageDirectlyResult(org.apache.rocketmq.common.protocol.body.ConsumeMessageDirectlyResult) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) ArrayList(java.util.ArrayList) ConsumeConcurrentlyStatus(org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus)

Aggregations

ConsumeMessageDirectlyResult (org.apache.rocketmq.common.protocol.body.ConsumeMessageDirectlyResult)15 MQClientException (org.apache.rocketmq.client.exception.MQClientException)6 MessageExt (org.apache.rocketmq.common.message.MessageExt)6 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 MQBrokerException (org.apache.rocketmq.client.exception.MQBrokerException)4 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)4 ConsumeMessageDirectlyResultRequestHeader (org.apache.rocketmq.common.protocol.header.ConsumeMessageDirectlyResultRequestHeader)4 RemotingException (org.apache.rocketmq.remoting.exception.RemotingException)4 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)4 SubCommandException (org.apache.rocketmq.tools.command.SubCommandException)4 ConsumeConcurrentlyContext (org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext)2 ConsumeConcurrentlyStatus (org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus)2 ConsumeOrderlyContext (org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyContext)2 ConsumeOrderlyStatus (org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyStatus)2 DefaultMQPushConsumerImpl (org.apache.rocketmq.client.impl.consumer.DefaultMQPushConsumerImpl)2 MQConsumerInner (org.apache.rocketmq.client.impl.consumer.MQConsumerInner)2 DefaultMQAdminExt (org.apache.rocketmq.tools.admin.DefaultMQAdminExt)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1