Reputation: 12447
If you publish an event in spring boot, is there an easy out of the box way to handle exceptions, or should events not be used if exceptions are to be handled? The question is for both sync and async listeners.
e.g. listeners:
@EventListener
public void handle(SomeEvent event){
// do stuff
}
@Async
@EventListener
public void handle(SomeOtherEvent event){
// do stuff
}
e.g. publishers
// stuff
publisher.publishEvent(new SomeEvent(data));
otherPublisher.publishEvent(new SomeOtherEvent(data));
Is there some best practice thing I should be doing in the method which publishes the event to catch any exceptions thrown out by the listener?
I assume for the aysnc one they are fire and forget, because you don't have a handle on the thread, but for sync ones, which are executed in the same thread, I assume that the caller waits for the sync event to be handled, in which case it may be possible to get a response?
Upvotes: 1
Views: 79