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;
}
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。