RocketMQ 常见异常处理

目录

MQClientException: No route info of this topic, TopicTest1

异常说明

解决办法

RemotingTooMuchRequestException: sendDefaultImpl call timeout

异常说明

解决办法


MQClientException: No route info of this topic, TopicTest1

异常说明

  • 在客户端的 Producer 运行起来准备发送消息时抛异常如下
  • “ No route info of this topic ” 异常产生的原因可能是,自己当时的原因恰好是第三条:
  1. Broker 禁止自动创建 Topic,且用户没有通过手工方式创建 Topic
  2. Broker 没有正确连接到 Name Server
  3. Producer 没有正确连接到 Name Server 
17:28:23.123 [main] DEBUG i.n.u.i.l.InternalLoggerFactory - Using SLF4J as the default logging framework
org.apache.rocketmq.client.exception.MQClientException: No route info of this topic, TopicTest1
See http://rocketmq.apache.org/docs/faq/ for further details.
	at org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl.sendDefaultImpl(DefaultMQProducerImpl.java:610)
17:28:29.595 [NettyClientSelector_1] INFO  RocketmqRemoting - closeChannel: close the connection to remote address[] result: true
	at org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl.send(DefaultMQProducerImpl.java:1223)
	at org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl.send(DefaultMQProducerImpl.java:1173)
	at org.apache.rocketmq.client.producer.DefaultMQProducer.send(DefaultMQProducer.java:214)
	at com.lct.quickstart.Producer.main(Producer.java:56)
	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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

解决办法

  • 排查1:Broker 禁止自动创建 Topic,且用户没有通过手工方式创建 Topic
  • 可以在 Rocket_HOME/distribution/target/apache-rocketmq 下执行 " sh bin/mqbroker -m " 来查看 broker 的配置参数
  • 如下所示,autoCreateTopicEnable=true 证明是没有问题的
[root@localhost apache-rocketmq]# sh ./bin/mqbroker -m
2018-08-12 01\:27\:28 INFO main - namesrvAddr=
2018-08-12 01\:27\:28 INFO main - brokerIP1=192.168.58.129
2018-08-12 01\:27\:28 INFO main - brokerName=localhost.localdomain
2018-08-12 01\:27\:28 INFO main - brokerClusterName=DefaultCluster
2018-08-12 01\:27\:28 INFO main - brokerId=0
2018-08-12 01\:27\:28 INFO main - autoCreateTopicEnable=true
2018-08-12 01\:27\:28 INFO main - autoCreateSubscriptionGroup=true
2018-08-12 01\:27\:28 INFO main - rejectTransactionMessage=false
2018-08-12 01\:27\:28 INFO main - fetchNamesrvAddrByAddressServer=false
2018-08-12 01\:27\:28 INFO main - transactionTimeOut=3000
2018-08-12 01\:27\:28 INFO main - transactionCheckMax=5
2018-08-12 01\:27\:28 INFO main - transactionCheckInterval=60000
2018-08-12 01\:27\:28 INFO main - storePathRootDir=/root/store
2018-08-12 01\:27\:28 INFO main - storePathCommitLog=/root/store/commitlog
2018-08-12 01\:27\:28 INFO main - flushIntervalCommitLog=500
2018-08-12 01\:27\:28 INFO main - commitIntervalCommitLog=200
2018-08-12 01\:27\:28 INFO main - flushCommitLogTimed=false
2018-08-12 01\:27\:28 INFO main - deleteWhen=04
2018-08-12 01\:27\:28 INFO main - fileReservedTime=72
2018-08-12 01\:27\:28 INFO main - maxTransferBytesOnMessageInMemory=262144
2018-08-12 01\:27\:28 INFO main - maxTransferCountOnMessageInMemory=32
2018-08-12 01\:27\:28 INFO main - maxTransferBytesOnMessageInDisk=65536
2018-08-12 01\:27\:28 INFO main - maxTransferCountOnMessageInDisk=8
2018-08-12 01\:27\:28 INFO main - accessMessageInMemoryMaxRatio=40
2018-08-12 01\:27\:28 INFO main - messageIndexEnable=true
2018-08-12 01\:27\:28 INFO main - messageIndexSafe=false
2018-08-12 01\:27\:28 INFO main - haMasterAddress=
2018-08-12 01\:27\:28 INFO main - brokerRole=ASYNC_MASTER
2018-08-12 01\:27\:28 INFO main - flushDiskType=ASYNC_FLUSH
2018-08-12 01\:27\:28 INFO main - cleanFileForciblyEnable=true
2018-08-12 01\:27\:28 INFO main - transientStorePoolEnable=false
[root@localhost apache-rocketmq]# 
  • 排查2:Broker 没有正确连接到 Name Server
  • 如下所示,启动 broker 的时候,只要看到了 The broker[localhost.localdomain, 192.168.58.129:10911] boot success. serializeType=JSON and name server is localhost:9876  字样就说明是成功的
[root@localhost apache-rocketmq]# nohup sh bin/mqbroker -n localhost:9876 &
[2] 3256
[1]   退出 143              nohup sh bin/mqbroker -n localhost:9876
[root@localhost apache-rocketmq]# nohup: 忽略输入并把输出追加到"nohup.out"
tail -f ~/logs/rocketmqlogs/broker.log 
2018-08-11 23:48:26 INFO main - load exist subscription group, SubscriptionGroupConfig [groupName=CID_ONSAPI_OWNER, consumeEnable=true, consumeFromMinEnable=true, consumeBroadcastEnable=true, retryQueueNums=1, retryMaxTimes=16, brokerId=
2018-08-11 23:48:31 WARN main - Load default discard message hook service: DefaultTransactionalMessageCheckListener
2018-08-11 23:48:31 INFO FileWatchService - FileWatchService service started
2018-08-11 23:48:31 INFO PullRequestHoldService - PullRequestHoldService service started
2018-08-11 23:48:31 INFO brokerOutApi_thread_1 - register broker to name server localhost:9876 OK
2018-08-11 23:48:31 INFO main - Start transaction service!
2018-08-11 23:48:31 INFO main - The broker[localhost.localdomain, 192.168.58.129:10911] boot success. serializeType=JSON and name server is localhost:9876
2018-08-11 23:48:41 INFO BrokerControllerScheduledThread1 - dispatch behind commit log 0 bytes
2018-08-11 23:48:41 INFO BrokerControllerScheduledThread1 - Slave fall behind master: 906412 bytes
2018-08-11 23:48:41 INFO brokerOutApi_thread_2 - register broker to name server localhost:9876 OK
  • 排查3:Producer 没有正确连接到 Name Server 
  • 当时一时糊涂 Linux 上开启了 Broker 端口是 9876,然后自己并没有在防护墙中开启此端口,所以导致客户端 Producer 无论如何也连接不上
  • 如下所示,命令分别含义是:
  1. 查看防护墙开放的端口,此时没有 9876
  2. 设置防火墙开放9876 端口
  3. 重新加载 firewall,修改配置后,必须重新加载才能生效:firewall-cmd --reload 
  4. 再次查看防火墙开放的端口,此时已有 9876
[root@localhost apache-rocketmq]# firewall-cmd --zone=public --list-ports
8090/tcp 80/tcp 8080/tcp
[root@localhost apache-rocketmq]# firewall-cmd --zone=public --add-port=9876/tcp --permanent
success
[root@localhost apache-rocketmq]# firewall-cmd --reload
success
[root@localhost apache-rocketmq]# firewall-cmd --zone=public --list-ports
9876/tcp 8090/tcp 80/tcp 8080/tcp
[root@localhost apache-rocketmq]# 

RemotingTooMuchRequestException: sendDefaultImpl call timeout

异常说明

  • 在客户端的 Producer 运行起来准备发送消息时抛异常如下
  • 因为使用的是虚拟机,设置内存也只有1G,所以从 Windows 上开发连接 虚拟机中的 nameServer 时要经过 Linux 系统的防火墙,而防火墙一般都会有超时的机制,在网络连接长时间不传输数据时,会关闭这个 TCP 的会话,关闭后再读写,就有可能导致这个异常。
16:22:37.403 [main] DEBUG i.n.u.i.l.InternalLoggerFactory - Using SLF4J as the default logging framework
16:22:40.994 [NettyClientSelector_1] INFO  RocketmqRemoting - closeChannel: close the connection to remote address[] result: true
Exception in thread "main" org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException: sendDefaultImpl call timeout
	at org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl.sendDefaultImpl(DefaultMQProducerImpl.java:588)
	at org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl.send(DefaultMQProducerImpl.java:1223)
	at org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl.send(DefaultMQProducerImpl.java:1173)
	at org.apache.rocketmq.client.producer.DefaultMQProducer.send(DefaultMQProducer.java:214)
	at com.lct.test.quickStart.Producer.main(Producer.java:28)
	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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
16:22:41.772 [NettyClientSelector_1] INFO  RocketmqRemoting - closeChannel: close the connection to remote address[] result: true
16:23:11.770 [NettyClientSelector_1] INFO  RocketmqRemoting - closeChannel: close the connection to remote address[] result: true

解决办法

  • 因为现在主要是熟练 RocketMQ 的 API,所以直接关闭了 Linux 的防火墙,实际中如果买的是如 阿里云的云主机,应该会好一些
[root@localhost ~]#  systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since 六 2018-08-11 23:20:53 CST; 56min ago
 Main PID: 877 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─877 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

8月 11 23:20:50 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall.....
8月 11 23:20:53 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall ...n.
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]# 
  • 如上所示防火墙是开的,下面指令关闭防火墙
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]#  systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since 日 2018-08-12 00:19:39 CST; 2s ago
  Process: 877 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)
 Main PID: 877 (code=exited, status=0/SUCCESS)

8月 11 23:20:50 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall.....
8月 11 23:20:53 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall ...n.
8月 12 00:19:38 localhost.localdomain systemd[1]: Stopping firewalld - dynamic firewall.....
8月 12 00:19:39 localhost.localdomain systemd[1]: Stopped firewalld - dynamic firewall ...n.
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]# 

 

 

 

你可能感兴趣的:(RocketMQ)