apache / apache/rocketmq-spring

Custom CGLIB RocketMQListener cannot be registered

Open
#532 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
2.3k
Forks
943
PR merge metrics
No merged PRs in 30d

Description

The code below is unable to register the listener
```
@RocketMQMessageListener(consumerGroup = "", topic = "test")
static class Receiver implements RocketMQListener {

@Override
public void onMessage(Object message) {

}
}

@Bean
public Receiver customEnhancer() {
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(Receiver.class);
enhancer.setCallback((MethodInterceptor) (o, method, objects, methodProxy) -> null);
return (Receiver) enhancer.create();
}
```
version: 2.2.3
I reviewed the logic of `RocketMQMessageListenerBeanPostProcessor` and found several issues.
1. `AopUtils.getTargetClass` does not traverse nested proxies, whereas in version 4.x, `AopProxyUtils.ultimateTargetClass` is used instead.
2. if a custom CGLIB listener does not implement the SpringProxy interface, the correct target class cannot be obtained.
![image](https://user-images.githubusercontent.com/13183021/221792519-4e6aec78-55a3-4311-870c-eddff72a4945.png)
![image](https://user-images.githubusercontent.com/13183021/221792625-34cfd87e-c18d-4275-8575-3c35bcdf2fa3.png)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in RocketMQMessageListenerBeanPostProcessor and trace how it obtains the listener target class from a custom CGLIB proxy. Compare the use of AopUtils.getTargetClass with the reported AopProxyUtils.ultimateTargetClass behavior, including proxies that do not implement SpringProxy. Done means the provided custom Receiver can be registered successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.