填坑1
docker按照了RocketMQ后把官网demo跑了一下,结果报了这个错误。
后来在https://github.com/apache/rocketmq/issues/504上面找到了解决方案。
原来启动broker的时候要额外的配置,否则broker不知道nameserver的存在。
编辑 broker.conf加入配置:
namesrvAddr = ip:port
官方的demo代码如下:
//Instantiate with a producer group name.
DefaultMQProducer producer = new
DefaultMQProducer("please_rename_unique_group_name");
// Specify name server addresses.
producer.setNamesrvAddr("localhost:9876");
//Launch the instance.
producer.start();
for (int i = 0; i < 100; i++) {
//Create a message instance, specifying topic, tag and message body.
Message msg = new Message("TopicTest" /* Topic */,
"TagA" /* Tag */,
("Hello RocketMQ " +
i).getBytes(RemotingHelper.DEFAULT_CHARSET) /* Message body */
);
//Call send message to deliver message to one of brokers.
SendResult sendResult = producer.send(msg);
System.out.printf("%s%n", sendResult);
}
//Shut down once the producer instance is not longer in use.
producer.shutdown();
天坑2
配置好了上面之后,可视化控制台已经能够看到信息了,但是damo还是跑不通,报错如下:
org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException: sendDefaultImpl call timeout
解决方法是在broker.conf 加入如下配置:
brokerIP1=宿主机ip