某天开发同事报说rocketmq连接不了,报以下错误:
org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException: sendDefaultImpl call timeout
本着凡事都要亲自验证的原则,我登陆rocketmq服务器做了测试:
[root@test-server rocketmq]# export NAMESRV_ADDR=localhost:9876 [root@test-server rocketmq]# sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer 16:38:41.675 [main] DEBUG i.n.u.i.l.InternalLoggerFactory - Using SLF4J as the default logging framework RocketMQLog:WARN No appenders could be found for logger (io.netty.util.internal.PlatformDependent0). RocketMQLog:WARN Please initialize the logger system properly. SendResult [sendStatus=SEND_OK, msgId=AC110001DBD94D7E1886279EDA940000, offsetMsgId=0A01066600002A9F0000000000D57A02, messageQueue=MessageQueue [topic=TopicTest, brokerName=nacos_test, queueId=3], queueOffset=2232] SendResult [sendStatus=SEND_OK, msgId=AC110001DBD94D7E1886279EDAB50001, offsetMsgId=0A01066600002A9F0000000000D57ACB, messageQueue=MessageQueue [topic=TopicTest, brokerName=nacos_test, queueId=0], queueOffset=2231] SendResult [sendStatus=SEND_OK, msgId=AC110001DBD94D7E1886279EDABA0002, offsetMsgId=0A01066600002A9F0000000000D57B94, messageQueue=MessageQueue [topic=TopicTest, brokerName=nacos_test, queueId=1], queueOffset=2231] SendResult [sendStatus=SEND_OK, msgId=AC110001DBD94D7E1886279EDAC50003, offsetMsgId=0A01066600002A9F0000000000D57C5D, messageQueue=MessageQueue [topic=TopicTest, brokerName=nacos_test, queueId=2], queueOffset=2233] SendResult [sendStatus=SEND_OK, msgId=AC110001DBD94D7E1886279EDAC90004, offsetMsgId=0A01066600002A9F0000000000D57D26, messageQueue=MessageQueue [topic=TopicTest, brokerName=nacos_test, queueId=3], queueOffset=2233]
[root@test-server rocketmq]# sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer 9EDD1600A6, CLUSTER=DefaultCluster, WAIT=true, TAGS=TagA}, body=[72, 101, 108, 108, 111, 32, 82, 111, 99, 107, 101, 116, 77, 81, 32, 49, 54, 54], transactionId='null'}]] ConsumeMessageThread_3 Receive New Messages: [MessageExt [brokerName=nacos_test, queueId=1, storeSize=203, queueOffset=2266, sysFlag=0, bornTimestamp=1620463122633, bornHost=/10.1.6.105:43826, storeTimestamp=1620463122631, storeHost=/10.1.6.102:10911, msgId=0A01066600002A9F0000000000D5EA2E, commitLogOffset=14019118, bodyCRC=174475622, reconsumeTimes=0, preparedTransactionOffset=0, toString()=Message{topic='TopicTest', flag=0, properties={MIN_OFFSET=0, MAX_OFFSET=2281, CONSUME_START_TIME=1620463196672, UNIQ_KEY=AC110001DBD94D7E1886279EDCC9008E, CLUSTER=DefaultCluster, WAIT=true, TAGS=TagA}, body=[72, 101, 108, 108, 111, 32, 82, 111, 99, 107, 101, 116, 77, 81, 32, 49, 52, 50], transactionId='null'}]]
发现生产者和消费者都可以正常工作,于是跟开发说我这边测试没问题,开发又把日志发过来,确实不行。于是我怀疑是不是就本机可以,别的机器访问他不行,我就在另外一台机器上做了测试,果然不行,报的错跟开发提供的一样。由于此前也没用过这玩意儿,不是很熟,遂百度和谷歌一通,总的来说有以下几个方法:
1、在broker.conf文件添加MQ的IP地址
[root@test-server rocketmq]# cat conf/broker.conf brokerClusterName = DefaultCluster brokerName = broker-a brokerId = 0 deleteWhen = 04 fileReservedTime = 48 brokerRole = ASYNC_MASTER flushDiskType = ASYNC_FLUSH namesrvAddr=10.1.6.105:9876 brokerIP1=10.1.6.105
试过,没效果
2、broker启动时候指定broker.conf配置文件,我原来没有指定,但是我另外一台也没有指定就可以,不懂
[root@test-server rocketmq]# nohup sh bin/mqbroker -n localhost:9876 autoCreateTopicEnable=true -c conf/broker.conf &
注意,我原来写成
[root@test-server rocketmq]# nohup sh bin/mqbroker -n 10.1.6.105:9876 autoCreateTopicEnable=true -c conf/broker.conf &
这样是不行的
3、修改lib/rocketmq-client-4.7.1.jar这个jar包里面的org/apache/rocketmq/client/impl/producer/DefaultMQProducerImpl.class这个class文件里面的默认超时参数,我找了好久没找到那个默认3000的超时时间
总结:折腾了一早上加差不多一下午才发现,原来是需要把方法2里面的broker启动参数的IP地址写成localhost:9876,我原来想当来的写成网卡IP