rocketmq icon indicating copy to clipboard operation
rocketmq copied to clipboard

Consumer rebalance problem when using docker container

Open vancefantasy opened this issue 7 years ago • 10 comments

BUG REPORT

  1. Please describe the issue you observed:

docker环境下,2个不同的consumer实例,生成的clientId是重复的,进而导致rebalance的结果混乱。(经过debug发现获取到的ip是一样的,怀疑跟rancher网络有关)

  1. Please tell us about your environment:

rocketmq client "4.3.0" java version "1.8.0_181" Docker version "18.09.0"

  1. Other information (e.g. detailed explanation, logs, related issues, suggestions how to fix, etc):

建议:改进ClientConfig类中instanceName的生成规则

vancefantasy avatar Jan 07 '19 07:01 vancefantasy

What's the current clientId generation rule in ClientConfig class? And how to reproduce it?

huanwei avatar Jan 09 '19 11:01 huanwei

@huanwei

clientId:

 public String buildMQClientId() {
    StringBuilder sb = new StringBuilder();
    sb.append(this.getClientIP());
    sb.append("@");
    sb.append(this.getInstanceName());
    if (!UtilAll.isBlank(this.unitName)) {
        sb.append("@");
        sb.append(this.unitName);
    }
    return sb.toString();
}

instanceName:

private String instanceName = System.getProperty("rocketmq.client.name", "DEFAULT");

public void changeInstanceNameToPID() {
    if (this.instanceName.equals("DEFAULT")) {
        this.instanceName = String.valueOf(UtilAll.getPid());
    }
}

在docker环境下(使用host模式),获取到的clientIp和pid都是一样的。当然clientIp一样的确切原因还没完全确认,可能和引入Rancher有关。

wx20190112-180557 2x

https://github.com/apache/rocketmq/pull/668

vancefantasy avatar Jan 12 '19 10:01 vancefantasy

I encountered the same problem. Under HOST networking mode, all dockers managed by Rancher are with the same docker0 IP, which is 172.17.0.1. Thus, RemotingUtil.getLocalAddress() always returns "172.17.0.1" for those dockers, which leads to collision between consumers with the same pid, if using default "IP@pid" clientId.

  • RocketMQ client Version: 4.3.2
  • Rancher Version: 1.16.10
  • Docker Version: 18.09.5

caigy avatar May 21 '19 11:05 caigy

@huanwei This is a known problem in the docker container if we deploy mutl-docker containers in the one machine.

vongosling avatar May 22 '19 02:05 vongosling

@caigy @huanwei if used Rancher to manage container, all docker will always return "172.17.0.1" when getLocalAddress, not only in bridge model, but also in host model, so I think it may be an issue caused by Rancher, so you can temporarily solve this problem by setting the instanceName.

duhenglucky avatar May 22 '19 03:05 duhenglucky

That's known issue caused by Rancher container network. Setting different instanceName should solve this problem, just as @duhenglucky suggested.

huanwei avatar May 22 '19 11:05 huanwei

Which version have been solved, I also meeting the same problem.

haycco avatar Jul 01 '19 11:07 haycco

Has this be fixed?

maixiaohai avatar Jan 19 '21 12:01 maixiaohai

除了通过手动自定义instanceName外,RocketMQ会做什么来兼容吗?还是不考虑兼容了?

Aaron-TangCode avatar Jan 07 '22 15:01 Aaron-TangCode

I would like a more general way to completely solve the problem of instance conflicts. https://github.com/apache/rocketmq/issues/3680

Git-Yang avatar Jan 08 '22 05:01 Git-Yang