rocketmq icon indicating copy to clipboard operation
rocketmq copied to clipboard

Console showed NOT_CONSUME_YET, but no consume actually?

Open linkypi opened this issue 5 years ago • 7 comments

rocketmq 4.8.0 单点部署在docker容器中,其中broker的配置文件中已配置brokerIP1 ,配置的是域名,而非实际IP地址:

brokerIP1=rmqbroker

如此配置就会导致问题的出现,若配置的是实际的IP则MQ消息状态正常。通过调试源码发现 rocketmq-tools 在判断消息是否已消费时未对域名进行解析导致。源码位置: org/apache/rocketmq/tools/admin/DefaultMQAdminExtImpl.java 中的 consumed 方法(linenum: 861) image

修复后: image 源码:

  while (it.hasNext()) {
       Entry<MessageQueue, OffsetWrapper> next = it.next();
       MessageQueue mq = next.getKey();
       if (mq.getTopic().equals(msg.getTopic()) && mq.getQueueId() == msg.getQueueId()) {
           BrokerData brokerData = ci.getBrokerAddrTable().get(mq.getBrokerName());
           if (brokerData != null) {
               final String msgStoreHost = RemotingUtil.socketAddress2String(msg.getStoreHost());
               final String brokerHost = getBrokerIpFromCluster(brokerData);
               log.info("============= msgHostIp: {}, msg.getStoreHost(): {} =============", msgStoreHost, brokerHost);

               if (msgStoreHost.equals(brokerHost)) {
                   log.info("next.getValue().getConsumerOffset(): {}, msg.getQueueOffset(): {}",
                           next.getValue().getConsumerOffset(), msg.getQueueOffset());
                   if (next.getValue().getConsumerOffset() > msg.getQueueOffset()) {
                       return true;
                   }
               }
           }
       }
   }

  private String getBrokerIpFromCluster(BrokerData brokerData ) throws UnknownHostException {
        String addr = brokerData.getBrokerAddrs().get(MixAll.MASTER_ID);
        final String[] arr = addr.split(":");
        final String host = arr[0];
        final String brokerIp = InetAddress.getAllByName(host)[0].getHostAddress() + ":" + arr[1];
        return brokerIp;
    }

希望尽早修复改问题。

此外还遇到另外一个问题,同样在docker环境下,消息中的 storeHost 是宿主机IP,而 brokerHost 却是容器IP,也会导致该问题,具体原因还在排查,暂时没找到原因.

linkypi avatar Feb 26 '21 02:02 linkypi

Mention a pull request by yourself and associate this issue.

fengyiluo avatar Feb 26 '21 07:02 fengyiluo

Thanks for your opt. you could make a pr as fengyihui suggested. BTW, we must keep in mind that InetAddress.getByName() implementation is blocking and standard Java libraries lack any non-blocking implementations.

vongosling avatar Feb 27 '21 03:02 vongosling

If rocketmq use docker or multiple network cards, rocketmq should initiate a UDP request to an external IP, and then get the IP address of the current server. rocketmq cannot use the system call of InetAddress API。It's just my idea

xhrg avatar Mar 16 '21 13:03 xhrg

遇到同样的问题,请问这是只是console显示有误,还是也会影响消息的正常消费?

ahaha-vip avatar Nov 03 '21 02:11 ahaha-vip

遇到同样的问题,请问这是只是 console 显示有误,还是也会影响消息的正常消费?

Message consumption is normal, but the console display is incorrect.

linkypi avatar Feb 24 '22 01:02 linkypi

This issue is stale because it has been open for 365 days with no activity. It will be closed in 3 days if no further activity occurs.

github-actions[bot] avatar Feb 25 '23 00:02 github-actions[bot]

This issue was closed because it has been inactive for 3 days since being marked as stale.

github-actions[bot] avatar Mar 01 '23 00:03 github-actions[bot]