File tree Expand file tree Collapse file tree 7 files changed +76
-14
lines changed
context/video/module/video Expand file tree Collapse file tree 7 files changed +76
-14
lines changed Original file line number Diff line number Diff line change 11package tv .codely ;
22
33import tv .codely .context .notification .module .push .application .create .SendPushToSubscribersOnVideoPublished ;
4- import tv .codely .context .video .module .video .domain . VideoPublished ;
4+ import tv .codely .context .video .module .video .application . create . VideoPublisher ;
55import tv .codely .shared .application .DomainEventSubscriber ;
66import tv .codely .shared .domain .EventBus ;
77import tv .codely .shared .infrastructure .bus .ReactorEventBus ;
@@ -13,14 +13,12 @@ public static void main(String[] args) {
1313 final Set <DomainEventSubscriber > subscribers = Set .of (
1414 new SendPushToSubscribersOnVideoPublished ()
1515 );
16-
1716 final EventBus eventBus = new ReactorEventBus (subscribers );
17+ final var videoPublisher = new VideoPublisher (eventBus );
1818
19- final var videoPublished = new VideoPublished (
20- "\uD83C \uDF89 New youtube.com/CodelyTV video title" ,
21- "This should be the video description \uD83D \uDE42 "
22- );
19+ final var videoTitle = "\uD83C \uDF89 New YouTube.com/CodelyTV video title" ;
20+ final var videoDescription = "This should be the video description \uD83D \uDE42 " ;
2321
24- eventBus .publish (videoPublished );
22+ videoPublisher .publish (videoTitle , videoDescription );
2523 }
2624}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ package tv .codely .context .video .module .video .application .create ;
2+
3+ import tv .codely .context .video .module .video .domain .Video ;
4+ import tv .codely .shared .domain .EventBus ;
5+
6+ public final class VideoPublisher {
7+ private final EventBus eventBus ;
8+
9+ public VideoPublisher (EventBus eventBus ) {
10+ this .eventBus = eventBus ;
11+ }
12+
13+ public void publish (String title , String description ) {
14+ final var video = Video .publish (title , description );
15+
16+ eventBus .publish (video .pullDomainEvents ());
17+ }
18+
19+ }
Original file line number Diff line number Diff line change 1+ package tv .codely .context .video .module .video .domain ;
2+
3+ import tv .codely .shared .domain .AggregateRoot ;
4+
5+ public final class Video extends AggregateRoot {
6+ private final String title ;
7+ private final String description ;
8+
9+ private Video (String title , String description ) {
10+ this .title = title ;
11+ this .description = description ;
12+ }
13+
14+ public static Video publish (String title , String description ) {
15+ var video = new Video (title , description );
16+
17+ var videoCreated = new VideoPublished (title , description );
18+
19+ video .record (videoCreated );
20+
21+ return video ;
22+ }
23+ }
Original file line number Diff line number Diff line change 1+ package tv .codely .shared .domain ;
2+
3+ import java .util .LinkedList ;
4+ import java .util .List ;
5+
6+ public abstract class AggregateRoot {
7+ private List <DomainEvent > recordedDomainEvents = new LinkedList <>();
8+
9+ final public List <DomainEvent > pullDomainEvents () {
10+ final var recordedDomainEvents = this .recordedDomainEvents ;
11+ this .recordedDomainEvents = new LinkedList <>();
12+
13+ return recordedDomainEvents ;
14+ }
15+
16+ final protected void record (DomainEvent event ) {
17+ recordedDomainEvents .add (event );
18+ }
19+ }
Original file line number Diff line number Diff line change 11package tv .codely .shared .domain ;
22
3+ import java .util .List ;
4+
35public interface EventBus {
4- void publish (DomainEvent event );
6+ void publish (final List < DomainEvent > events );
57}
Original file line number Diff line number Diff line change 77import tv .codely .shared .application .DomainEventSubscriber ;
88import tv .codely .shared .domain .DomainEvent ;
99
10+ import java .util .Arrays ;
11+ import java .util .List ;
1012import java .util .Set ;
1113
1214import static reactor .bus .selector .Selectors .$ ;
@@ -21,7 +23,11 @@ public ReactorEventBus(final Set<DomainEventSubscriber> subscribers) {
2123 }
2224
2325 @ Override
24- public void publish (final DomainEvent event ) {
26+ public void publish (final List <DomainEvent > events ) {
27+ events .forEach (this ::publish );
28+ }
29+
30+ private void publish (final DomainEvent event ) {
2531 Class <? extends DomainEvent > eventIdentifier = event .getClass ();
2632 Event <DomainEvent > wrappedEvent = Event .wrap (event );
2733
You can’t perform that action at this time.
0 commit comments