I have an interface for a Service object that looks something like the following (simplified for brevity):
public interface ItemService {
public Item getItemB
In contrast to Wouter Coekaerts I understand that you are asking for an way to send notifications that will be only submitted to the reciver if the transaction in which they are created was succesfull. -- So you are looking for something that is similar to the transactional CDI-Event mechanism.
My idea to solve it is this way:
To forward or delete the events I would first have a lookt at the spring transaction mechanism. If there is no way to extend it, you could write an AOP aspect that forward the events if a method annotated with @Transactional
was leaving wihtout an (Runtime)Exception. But if the @Transactional
annotated Method was leaving with an (Runtime)Exception then delete the events from the list.