RocketMQ 消费抛出Message not exist异常-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文
阿里云
为了无法计算的价值
打开APP
阿里云APP内打开

RocketMQ 消费抛出Message not exist异常

1、使用阿里云java http client 版本:1.0.1

2、消费部分代码

                     // 长轮询消费消息
                    // 长轮询表示如果topic没有消息则请求会在服务端挂住3s,3s内如果有消息可以消费则立即返回
                    messages = consumerId.consumeMessage(
                            3,// 一次最多消费3条(最多可设置为16条)
                            3// 长轮询时间3秒(最多可设置为30秒)
                    );
                    // 没有消息
                    if (messages == null || messages.isEmpty()) {
                        System.out.println(Thread.currentThread().getName() + ": no new message, continue!");
                        continue;
                    }

3、异常信息


com.aliyun.mq.http.common.ServiceException: <?xml version="1.0" ?>
<Error xmlns="http://mq.aliyuncs.com/doc/v1">
  <Code>MessageNotExist</Code>
  <Message>Message not exist.</Message>
  <RequestId>5EE31D253842397B6D765BA3</RequestId>
  <HostId>http://xxxx.mqrest.cn-qingdao.aliyuncs.com</HostId>
</Error>
	at com.aliyun.mq.http.common.http.ExceptionResultParser.parse(ExceptionResultParser.java:46)
	at com.aliyun.mq.http.common.http.ExceptionResultParser.parse(ExceptionResultParser.java:12)
	at com.aliyun.mq.http.common.http.HttpCallback.handleResult(HttpCallback.java:140)
	at com.aliyun.mq.http.common.http.HttpCallback.buildResponseMessage(HttpCallback.java:113)
	at com.aliyun.mq.http.common.http.HttpCallback.completed(HttpCallback.java:74)
	at com.aliyun.mq.http.common.http.HttpCallback.completed(HttpCallback.java:22)
	at org.apache.http.concurrent.BasicFuture.completed(BasicFuture.java:122)
	at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.responseCompleted(DefaultClientExchangeHandlerImpl.java:181)
	at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.processResponse(HttpAsyncRequestExecutor.java:448)
	at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.inputReady(HttpAsyncRequestExecutor.java:338)
	at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:265)
	at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:81)
	at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:39)
	at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:114)
	at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:162)
	at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:337)
	at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315)
	at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:276)
	at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104)
	at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:591)
	at java.base/java.lang.Thread.run(Thread.java:830)

4、从异常信息来看应该是没有消息,但sdk中没有消费到看代码是根据code过滤了,但不知道为什么这个code不是MessageNotExist


 try {
            ConsumeMessageAction action = new ConsumeMessageAction(serviceClient, credentials, endpoint);
            request.setRequestPath(topicURL + "/" + Constants.LOCATION_MESSAGES);
            return action.executeWithCustomHeaders(request, null);
        } catch (ServiceException e) {
            if (Constants.CODE_MESSAGE_NOT_EXIST.equals(e.getErrorCode())) {
                return null;
            } else {
                throw e;
            }
        }

展开
收起
jiankunking 2020-06-12 14:19:06 4997 0
2 条回答
写回答
取消 提交回答
  • brandonyou

    我也是,有时候正常有时候这样。

    2021-03-22 23:25:19
    赞同 展开评论 打赏
  • 不语奈何
    精于基础,广于工具,熟于业务。

    应该是长时间无消息导致的

    2020-06-12 17:35:17
    赞同 展开评论 打赏
问答排行榜
最热
最新
相关电子书
更多
RocketMQ Summit 2022 开源生态发展
立即下载
技术揭秘:RocketMQ 5.0 云原生架构升级之路
立即下载
行业实践:RocketMQ 业务集成典型行业应用和实践
立即下载