单机环境搭建
依赖
64 位操作系统,Linux/ Unix/Mac OS
64位JDK 1.8+
Maven 3.2.x
Git
代码下载
1 | git clone https://github.com/apache/rocketmq.git |
项目构建
1 | cd rocketmq |
启动 NameServer
1 | 启动NameServer |
启动 Broker
1 | 启动Broker |
发送和接收消息
生产者发送消息
1 | export NAMESRV_ADDR=localhost:9876 |
消费者消费消息
1 | sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer |
关闭服务
1 | 关闭 broker |
RocketMQ - 控制台
- RocketMQ扩展组件: http://github.com/apache/rocketmq-externals/tree/master/
- 控制台使用:直接引入工程后,修改配置文件即可
1 | git clone https://github.com/apache/rocketmq-externals.git |
SpringBoot 整合流程三步骤
1 | 三流程,添加依赖,配置注解,配置属性 |
Spring 消息编程模型
RocketMQ: RocketMQTemplate 来 convertAndSend 提示 org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException: sendDefaultImpl call timeout
RemotingTooMuchRequestException
1 | public class RemotingTooMuchRequestException extends RemotingException { |
sendMessage
1 | public class MQClientAPIImpl { |
sendKernelImpl
1 | public class DefaultMQProducerImpl implements MQProducerInner { |
sendDefaultImpl
1 | public class DefaultMQProducerImpl implements MQProducerInner { |
- RemotingTooMuchRequestException继承了RemotingException;MQClientAPIImpl的sendMessage方法在调用sendMessageAsync或者sendMessageSync方法之前会先判断是否已经超时,如果超时则抛出RemotingTooMuchRequestException(“sendMessage call timeout”)
- DefaultMQProducerImpl的sendKernelImpl方法在communicationMode为ASYNC或者SYNC时,在执行mQClientFactory.getMQClientAPIImpl().sendMessage之前也会先判断是否超时,超时则抛出RemotingTooMuchRequestException(“sendKernelImpl call timeout”)
- DefaultMQProducerImpl的sendDefaultImpl方法内部会通过selectOneMessageQueue选择MessageQueue,然后通过sendKernelImpl来执行消息发送,在调用sendKernelImpl方法之前会先判断是否超时,超时的话则设置callTimeout为true,跳出循环,之后抛出RemotingTooMuchRequestException(“sendDefaultImpl call timeout”);sendSelectImpl方法通过MessageQueueSelector来选择MessageQueue,在通过sendKernelImpl发送消息之前会判断是否超时,超时则抛出RemotingTooMuchRequestException(“sendSelectImpl call timeout”)
部分参考
聊聊rocketmq的RemotingTooMuchRequestException
两个容易忽悠的点
- 需要配置 nameserver, broker 内存大小,默认是4G,服务器内存不够的话,需要修改大小,否则会导致启动失败
- org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException: sendDefaultImpl call timeout ,vim broker.conf :新增 brokerIP1=106.11.xx.xx,nohup sh bin/mqbroker -n 106.11.xx.xx:9876 -c conf/broker.conf &
1 | 3.7. 修改启动脚本参数【两台机器】 |
1 | vim broker.config >> brokerIP1=106.11.xx.xx |