I was reading through Spring Framework documentation and found a section on raising events in Spring using ApplicationContext
. After reading a few paragraphs I found that Spring events are raised synchronously. Is there any way to raise asynchronous events? your help is much appreciated. I am looking something similar which would help me to complete my module.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Alternative notification strategies can be achieved by implementing
ApplicationEventMulticaster
(see Javadoc) and its underlying (helper) class hierarchy. Typically you use either a JMS based notification mechanism (as David already suggested) or attach to Spring'sTaskExecuter
abstraction (see Javadoc).Simplest asynchronous
ApplicationListener
:Publisher:
Listener:
You should subclass
ApplicationEvent
with your specific events. You can configureSimpleApplicationEventMulticaster
and itstaskExecutor
in an XML file.You might want to implement
ApplicationEventPublisherAware
in your listener class and pass a source object (instead of empty string) in the event constructor.Try this override the ApplicationEventMulticaster bean in resources.groovy so that it uses a thread pool:
Some thing like this worked for me, i.e. I used
Spring itself (AFAIK) work synchronously, but what you can do is to create your own ApplicationListener proxy - a class that implements this interface but instead of handling the event it just delegates it by sending to another (or new) thread, sending JMS message, etc.