Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RocketMQMessageListenerBeanPostProcessor implements SmartLifecycle start() #672

Open
mdjava opened this issue Jul 30, 2024 · 0 comments
Open

Comments

@mdjava
Copy link

mdjava commented Jul 30, 2024

@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
	 Class<?> targetClass = AopUtils.getTargetClass(bean);
     RocketMQMessageListener ann = targetClass.getAnnotation(RocketMQMessageListener.class);
     if (ann != null) {
         RocketMQMessageListener enhance = enhance(targetClass, ann);
         if (listenerContainerRegistrar != null) {
        	 log.warn("=== 111 ====");
             listenerContainerRegistrar.registerContainer(beanName, bean, enhance);
         }
     }
    return bean;
}

@Override
public int getPhase() {
    return Integer.MAX_VALUE - 2000;
}

@Override
public void start() {
    if (!isRunning()) {
        this.setRunning(true);
        log.warn("=== 222 ====");
        listenerContainerRegistrar.startContainer();
    }
}

1、单独使用spring-boot 2.7.18 registerContainer start 顺序正确可正常使用。
执行顺序
=== 111 ==== 先执行
=== 222 ==== 后执行
registerContainer 注册正常。
start 正常。
2、主要依赖如下
spring-cloud 2021.0.6
spring-cloud-starter-alibaba 2021.0.6.1
spring-boot 2.7.18
执行顺序
=== 222 ==== 先执行
=== 111 ==== 后执行
registerContainer 注册正常。
start 未能正常执行。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant