{"record":{"id":"8b4070fab9bc242b","repo":"apache/rocketmq","slug":"the-producer-group-producergroup-has-been-creat","errorCode":null,"errorMessage":"The producer group[{producerGroup}] has been created before, specify another name please.","messagePattern":"The producer group\\[(.+?)\\] has been created before, specify another name please\\.","errorType":"exception","errorClass":"MQClientException","httpStatus":null,"severity":"error","filePath":"client/src/main/java/org/apache/rocketmq/client/impl/producer/DefaultMQProducerImpl.java","lineNumber":261,"sourceCode":"    public void start(final boolean startFactory) throws MQClientException {\n        switch (this.serviceState) {\n            case CREATE_JUST:\n                this.serviceState = ServiceState.START_FAILED;\n\n                this.checkConfig();\n\n                if (!this.defaultMQProducer.getProducerGroup().equals(MixAll.CLIENT_INNER_PRODUCER_GROUP)) {\n                    this.defaultMQProducer.changeInstanceNameToPID();\n                }\n\n                this.mQClientFactory = MQClientManager.getInstance().getOrCreateMQClientInstance(this.defaultMQProducer, rpcHook);\n\n                defaultMQProducer.initProduceAccumulator();\n\n                boolean registerOK = mQClientFactory.registerProducer(this.defaultMQProducer.getProducerGroup(), this);\n                if (!registerOK) {\n                    this.serviceState = ServiceState.CREATE_JUST;\n                    throw new MQClientException(\"The producer group[\" + this.defaultMQProducer.getProducerGroup()\n                        + \"] has been created before, specify another name please.\" + FAQUrl.suggestTodo(FAQUrl.GROUP_NAME_DUPLICATE_URL),\n                        null);\n                }\n\n                if (startFactory) {\n                    mQClientFactory.start();\n                }\n\n                this.initTopicRoute();\n\n                this.mqFaultStrategy.startDetector();\n\n                log.info(\"the producer [{}] start OK. sendMessageWithVIPChannel={}\", this.defaultMQProducer.getProducerGroup(),\n                    this.defaultMQProducer.isSendMessageWithVIPChannel());\n                this.serviceState = ServiceState.RUNNING;\n                break;\n            case RUNNING:\n            case START_FAILED:","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/apache/rocketmq/blob/293f5885719fc4aa3619446a1900f58ccfcfdd29/client/src/main/java/org/apache/rocketmq/client/impl/producer/DefaultMQProducerImpl.java#L243-L279","documentation":"MQClientException thrown from DefaultMQProducerImpl.start() when registerProducer(group, this) returns false, i.e. a producer with the same group name is already registered in this JVM's MQClientInstance (keyed by clientId). RocketMQ requires producer group names to be unique within a client instance because the group maps 1:1 to the producer implementation inside the shared factory. The companion FAQ link points at the duplicate group name page.","triggerScenarios":"Creating and starting two DefaultMQProducer instances with the same producerGroup and the same clientId (same unit name / instance settings) in one JVM; starting a producer, shutting it down incompletely, and starting a new one with the same group before unregistration completes; re-start() after a partially failed start.","commonSituations":"Singleton wrappers (Spring beans, connection pools) that lazily create a producer per request without caching by group name; code that calls producer.start() in a loop or in @PostConstruct of a prototype-scoped bean; tests that build a new producer per test method but share the JVM and instance name.","solutions":["Use one shared DefaultMQProducer per group name per JVM (cache/singleton it) instead of creating new instances","If you truly need multiple producers, give each a distinct producerGroup name","Ensure producer.shutdown() fully ran (it unregisters the group) before creating a replacement with the same group","Set a distinct instanceName/unitName on the ClientConfig so each producer gets a different MQClientInstance if isolation is intended"],"exampleFix":"// before\nDefaultMQProducer p = new DefaultMQProducer(\"order-producer\");\np.start(); // called again elsewhere with same group -> exception\n// after\nprivate static volatile DefaultMQProducer shared;\nif (shared == null) { shared = new DefaultMQProducer(\"order-producer\"); shared.start(); }","handlingStrategy":"validation","validationCode":" private final Set<String> registeredGroups = ConcurrentHashMap.newKeySet();\npublic DefaultMQProducer getOrCreate(String group) throws MQClientException {\n    if (!registeredGroups.add(group)) {\n        return existingProducers.get(group); // reuse, don't create duplicate\n    }\n    DefaultMQProducer p = new DefaultMQProducer(group);\n    p.start();\n    existingProducers.put(group, p);\n    return p;\n}","typeGuard":null,"tryCatchPattern":"try {\n    producer.start();\n} catch (MQClientException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"has been created before\")) {\n        return existingProducerFor(group); // reuse the already-registered instance\n    }\n    throw e;\n}","preventionTips":["Cache producers by group name in a registry/map; never construct a second producer for the same group in one JVM","Wrap producers in a singleton bean (Spring) so lifecycle is managed once","Always call shutdown() in @PreDestroy / finally so group names are released before re-creation","Give producers distinct instanceName via setInstanceName when intentional isolation is needed"],"tags":["rocketmq","producer","duplicate-registration","lifecycle"],"backgroundTag":null,"analyzedSha":"293f5885719fc4aa3619446a1900f58ccfcfdd29","analyzedAt":"2026-08-14T11:50:13.822Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}