The producer group has been created before

为什么80%的码农都做不了架构师?>>>   hot3.png

编写一个help类

public class RunTimeUtil {
    private static AtomicInteger index = new AtomicInteger();
    public static int getPid() {
        String info = getRunTimeInfo();
        int pid = (new Random()).nextInt();
        int index = info.indexOf("@");
        if(index > 0) {
            pid = Integer.parseInt(info.substring(0, index));
        }
        return pid;
    }
    public static String getRunTimeInfo() {
        RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
        String info = runtime.getName();
        return info;
    }
    public static String getRocketMqUniqeInstanceName() {
        return "pid" + getPid() + "_index" + index.incrementAndGet();
    }
}
consumer.setInstanceName(RunTimeUtil.getRocketMqUniqeInstanceName());

即可解决上述问题

 

转载于:https://my.oschina.net/gaomq/blog/1920583

你可能感兴趣的:(The producer group has been created before)