lilinjiang opened a new issue, #632:
URL: https://github.com/apache/rocketmq-spring/issues/632
报错日志:
java.lang.NullPointerException: null
at
org.apache.rocketmq.spring.core.RocketMQTemplate.syncSend(RocketMQTemplate.java:708)
问题原因:
经过排查源码发现
监听者准备完成的时机早于生产者准备完成。导致项目启动时监听者监听到消息后立即通过@ExtRocketMQTemplateConfiguration注解扩展的RocketMQTemplate发送消息产生空指针,因为此时RocketMQTemplate的producer(实际的生产者)属性等于null
监听者是基于BeanPostProcessor 的 postProcessAfterInitialization 方法实现启动监听
生产者是基于SmartInitializingSingleton的afterSingletonsInstantiated
方法实现设置真正的生产者(晚于监听者准备好)
<img width="1217" alt="监听者图片"
src="https://github.com/apache/rocketmq-spring/assets/36615541/b097d0aa-9ab2-4683-a27e-ddfc077f10db">
<img width="1155" alt="生产者图片"
src="https://github.com/apache/rocketmq-spring/assets/36615541/c23e8186-5c2c-46b1-982d-8480667116c3">
解决办法:
ListenerContainerConfiguration 新增
private final List<DefaultRocketMQListenerContainer> containers = new
ArrayList<>();
并修改以下代码
<img width="1098" alt="Snipaste_2024-02-22_22-05-43"
src="https://github.com/apache/rocketmq-spring/assets/36615541/fa3e4fc4-7ab0-4d96-87a4-adaef53d55fe">
RocketMQMessageListenerBeanPostProcessor 增加实现 SmartLifecycle
并修改以下代码

--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]