RocKetMQ : MQClientException: The producer service state not OK, CREATE_JUST

1. 背景


启动RocketMQ,然后使用客户端发送数据失败

2. 启动

lcc@lcc rocketmq-all-4.5.0-bin-release$ sh bin/mqnamesrv
Java HotSpot(TM) 64-Bit Server VM warning: Using the DefNew young collector with the CMS collector is deprecated and will likely be removed in a future release
Java HotSpot(TM) 64-Bit Server VM warning: UseCMSCompactAtFullCollection is deprecated and will likely be removed in a future release.
Java HotSpot(TM) 64-Bit Server VM warning: Cannot open file /dev/shm/rmq_srv_gc.log due to No such file or directory

The Name Server boot success. serializeType=JSON

启动Broker

lcc@lcc rocketmq-all-4.5.0-bin-release$ sh bin/mqbroker -n localhost:9876
Java HotSpot(TM) 64-Bit Server VM warning: Cannot open file /dev/shm/mq_gc_pid1469.log due to No such file or directory

The broker[lcc, 192.168.10.154:10911] boot success. serializeType=JSON and name server is localhost:9876

3.程序

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;
import org.junit.Test;

import static org.junit.Assert.*;

public class ProducerDemoTest {

    @Test
    public void producerTest() throws InterruptedException, RemotingException, MQClientException, MQBrokerException {
        DefaultMQProducer producer = new DefaultMQProducer("producer_group");
        producer.setNamesrvAddr("localhost:9876");
        for (int i = 0; i < 10; i++) {
            byte[] message = ("hello RocketMQ" + i).getBytes();
            Message msg = new Message("TopicTest",message);
            SendResult sendResult = producer.send(msg);
            System.out.printf("%s%n",sendResult);
        }
    }

}

运行报错如下

org.apache.rocketmq.client.exception.MQClientException: The producer service state not OK, CREATE_JUST
See http://rocketmq.apache.org/docs/faq/ for further details.

	at org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl.makeSureStateOK(DefaultMQProducerImpl.java:413)
	at org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl.sendDefaultImpl(DefaultMQProducerImpl.java:522)
	at org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl.send(DefaultMQProducerImpl.java:1280)
	at org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl.send(DefaultMQProducerImpl.java:1226)
	at org.apache.rocketmq.client.producer.DefaultMQProducer.send(DefaultMQProducer.java:283)
	at com.rocketmq.test.producer.ProducerDemoTest.producerTest(ProducerDemoTest.java:22)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)


最后查询说 网络不稳定的时候会出现这个问题,我的却是少写了一行代码

 @Test
    public void producerTest() throws InterruptedException, RemotingException, MQClientException, MQBrokerException {
        DefaultMQProducer producer = new DefaultMQProducer("producer_group");
        producer.setNamesrvAddr("localhost:9876");
        producer.start();
        for (int i = 0; i < 10; i++) {
            byte[] message = ("hello RocketMQ" + i).getBytes();
            Message msg = new Message("TopicTest",message);
            SendResult sendResult = producer.send(msg);
            System.out.printf("%s%n",sendResult);
        }
    }

可以看到发送成功

SendResult [sendStatus=SEND_OK, msgId=C0A80A9A06D418B4AAC263EDE38C0000, offsetMsgId=C0A80A9A00002A9F000000000015F590, messageQueue=MessageQueue [topic=TopicTest, brokerName=lcc, queueId=2], queueOffset=2000]
SendResult [sendStatus=SEND_OK, msgId=C0A80A9A06D418B4AAC263EDE3C50001, offsetMsgId=C0A80A9A00002A9F000000000015F637, messageQueue=MessageQueue [topic=TopicTest, brokerName=lcc, queueId=3], queueOffset=2000]
SendResult [sendStatus=SEND_OK, msgId=C0A80A9A06D418B4AAC263EDE3CA0002, offsetMsgId=C0A80A9A00002A9F000000000015F6DE, messageQueue=MessageQueue [topic=TopicTest, brokerName=lcc, queueId=4], queueOffset=0]
SendResult [sendStatus=SEND_OK, msgId=C0A80A9A06D418B4AAC263EDE3D40003, offsetMsgId=C0A80A9A00002A9F000000000015F785, messageQueue=MessageQueue [topic=TopicTest, brokerName=lcc, queueId=5], queueOffset=0]
SendResult [sendStatus=SEND_OK, msgId=C0A80A9A06D418B4AAC263EDE3DA0004, offsetMsgId=C0A80A9A00002A9F000000000015F82C, messageQueue=MessageQueue [topic=TopicTest, brokerName=lcc, queueId=6], queueOffset=0]
SendResult [sendStatus=SEND_OK, msgId=C0A80A9A06D418B4AAC263EDE3DF0005, offsetMsgId=C0A80A9A00002A9F000000000015F8D3, messageQueue=MessageQueue [topic=TopicTest, brokerName=lcc, queueId=7], queueOffset=0]
SendResult [sendStatus=SEND_OK, msgId=C0A80A9A06D418B4AAC263EDE3E40006, offsetMsgId=C0A80A9A00002A9F000000000015F97A, messageQueue=MessageQueue [topic=TopicTest, brokerName=lcc, queueId=0], queueOffset=2000]
SendResult [sendStatus=SEND_OK, msgId=C0A80A9A06D418B4AAC263EDE3EB0007, offsetMsgId=C0A80A9A00002A9F000000000015FA21, messageQueue=MessageQueue [topic=TopicTest, brokerName=lcc, queueId=1], queueOffset=2000]
SendResult [sendStatus=SEND_OK, msgId=C0A80A9A06D418B4AAC263EDE3EF0008, offsetMsgId=C0A80A9A00002A9F000000000015FAC8, messageQueue=MessageQueue [topic=TopicTest, brokerName=lcc, queueId=2], queueOffset=2001]
SendResult [sendStatus=SEND_OK, msgId=C0A80A9A06D418B4AAC263EDE3F50009, offsetMsgId=C0A80A9A00002A9F000000000015FB6F, messageQueue=MessageQueue [topic=TopicTest, brokerName=lcc, queueId=3], queueOffset=2001]

好尴尬呀

你可能感兴趣的:(大数据-RocketMQ)