Tricky
Asynchronous behavior is added through proxying.
Spring provides a proxy server that wraps the actual object and makes the actual call in a separate thread.
It looks something like this (except that most of them are executed dynamically using CGLIB or JDK and Spring handlers)
class ProxyListener extends ActivityMessageListener { private ActivityMessageListener real; public ProxyListener(ActivityMessageListener real) { this.real = real; } TaskExecutor executor;
Now in the Spring world, you will have a reference to the proxy object, not to the ActivityMessageListener . it
ActivityMessageListener proxy = applicationContext.getBean(ActivityMessageListener.class);
will return a link to the ProxyListener . Then, through polymorphism, the doReceive call will go to the overriden Proxy#doReceive , which will call the ActivityMessageListener#doReceive through delegation, and you will get your asynchronous behavior.
However, you are in half the world of Spring.
Here
public ActivityMessageListener() { MessageBusUtil.addQueue(MKTDestinationNames.ACTIVITY_REGISTRY, this); }
this link actually refers to the real ActivityMessageListener , not the proxy. Therefore, when, presumably, you send your message by bus here.
MessageBusUtil.sendMessage(MKTDestinationNames.ACTIVITY_REGISTRY, message);
you send it to a real object that does not have proxy asynchronous behavior.
The complete Spring solution should be for MessabeBus (and / or its queue) to be Spring beans, in which you can enter the whole process (proxy, automatically, initialized) beans.
In fact, since CGLIB proxies are really just subclasses of your types, so the ProxyListener described above ProxyListener also add itself to the bus, as the super constructor will be called. It would seem that only one MessageListener can register itself with a key, for example MKTDestinationNames.ACTIVITY_REGISTRY . If this is not the case, you will need to show more of this code for explanation.
In your test, if you do
activityMessageListener.doReceive(message);
you should see that the asynchronous behavior with the ActivityMessageListener should contain a link to the proxy.