-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from barsifedron/29-allow-some-domain-events-t…
…o-be-processed-within-the-current-transaction-and-others-to-be-processed-after Issue 29 : clean ups + added docs for clarification
- Loading branch information
Showing
10 changed files
with
179 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...in/java/com/barsifedron/candid/cqrs/spring/domainevent/ToProcessAfterMainTransaction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
package com.barsifedron.candid.cqrs.spring.domainevent; | ||
|
||
/** | ||
* A marker interface. | ||
* | ||
* If the bus allows it, domain event handlers marked with it will be executed AFTER | ||
* the main database transaction | ||
*/ | ||
public interface ToProcessAfterMainTransaction { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...dron/candid/cqrs/happy/domainevents/ItemBorrowedDomainEventHandler_InMainTransaction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.barsifedron.candid.cqrs.happy.domainevents; | ||
|
||
import com.barsifedron.candid.cqrs.domainevent.DomainEventHandler; | ||
import com.barsifedron.candid.cqrs.domainevent.ToProcessAfterMainTransaction; | ||
import com.barsifedron.candid.cqrs.happy.command.BorrowItemCommandHandler; | ||
import com.barsifedron.candid.cqrs.happy.domain.Email; | ||
import com.barsifedron.candid.cqrs.happy.domain.EmailRepository; | ||
|
||
import javax.inject.Inject; | ||
import java.util.logging.Logger; | ||
|
||
public class ItemBorrowedDomainEventHandler_InMainTransaction implements DomainEventHandler<ItemBorrowedDomainEvent> { | ||
|
||
static Logger LOGGER = Logger.getLogger(ItemBorrowedDomainEventHandler_InMainTransaction.class.getName()); | ||
|
||
@Inject | ||
public ItemBorrowedDomainEventHandler_InMainTransaction() { | ||
} | ||
|
||
@Override | ||
public void handle(ItemBorrowedDomainEvent event) { | ||
|
||
LOGGER.info("" + | ||
"This event handler executes WITHIN the main transaction" + | ||
"as it makes NO use of the marker interface : ToProcessAfterMainTransaction"); | ||
|
||
// add your code that needs to be processed in the main transaction here. | ||
|
||
// ... | ||
// ... | ||
|
||
|
||
} | ||
|
||
@Override | ||
public Class<ItemBorrowedDomainEvent> listenTo() { | ||
return ItemBorrowedDomainEvent.class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...com/barsifedron/candid/cqrs/happy/domainevents/NewMemberRegisteredDomainEventHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.barsifedron.candid.cqrs.happy.domainevents; | ||
|
||
import com.barsifedron.candid.cqrs.domainevent.DomainEventHandler; | ||
import com.barsifedron.candid.cqrs.happy.domain.Email; | ||
import com.barsifedron.candid.cqrs.happy.domain.EmailRepository; | ||
|
||
import javax.inject.Inject; | ||
|
||
public class NewMemberRegisteredDomainEventHandler implements DomainEventHandler<NewMemberRegisteredDomainEvent> { | ||
|
||
private final EmailRepository emailRepository; | ||
|
||
@Inject | ||
public NewMemberRegisteredDomainEventHandler(EmailRepository emailRepository) { | ||
this.emailRepository = emailRepository; | ||
} | ||
|
||
@Override | ||
public void handle(NewMemberRegisteredDomainEvent event) { | ||
|
||
Email email = Email | ||
.builder() | ||
.email(event.email) | ||
.body(String.format( | ||
"" | ||
+ "Hi %s.\n" | ||
+ "You are now a member of the happy neighborhood community.\n" | ||
+ "Your member id is %s.\n" | ||
+ "We are glad to have you in our team!.\\n", | ||
event.firstname, | ||
event.memberId)) | ||
.status(Email.EMAIL_STATUS.TO_BE_SENT) | ||
.build(); | ||
|
||
|
||
/** | ||
* We store the email to be sent. Another process will manage retrieval and actually sending of these | ||
*/ | ||
emailRepository.add(email); | ||
|
||
} | ||
|
||
|
||
@Override | ||
public Class<NewMemberRegisteredDomainEvent> listenTo() { | ||
return NewMemberRegisteredDomainEvent.class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters