Skip to content
This repository was archived by the owner on Nov 6, 2023. It is now read-only.

Commit 1803875

Browse files
authored
Merge pull request #2 from CodelyTV/reactor
Add a simple implementation of an event bus using reactor Co-authored-by: Javier Ferrer <javier.mailserio@gmail.com>
2 parents ca8054b + 72f600c commit 1803875

File tree

22 files changed

+327
-27
lines changed

22 files changed

+327
-27
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Gradle
22
.gradle
33
build/
4+
out/
45

56
# Ignore Gradle GUI config
67
gradle-app.setting

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Take a look, play and have fun with it!
2121
`./gradlew assemble --warning-mode all`
2222
2. Run the tests and plugins verification tasks:
2323
`./gradlew check --warning-mode all`
24+
3. Execute the main application entrypoint:
25+
`./gradlew run --warning-mode all`
2426
4. Start developing!
2527

2628
## 🤔 How to update dependencies

build.gradle

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
apply plugin: 'java'
2+
apply plugin: 'application'
23

34
sourceCompatibility = 1.11
45
targetCompatibility = 1.11
56

67
repositories {
78
mavenCentral()
9+
jcenter()
810
}
911

1012
dependencies {
11-
testCompile('org.junit.jupiter:junit-jupiter-api:5.3.2')
12-
testRuntime('org.junit.jupiter:junit-jupiter-engine:5.3.2')
13+
// Prod
14+
implementation 'io.projectreactor:reactor-bus:2.0.8.RELEASE'
15+
16+
// Test
17+
testCompile "org.mockito:mockito-core:2.+"
18+
testCompile 'org.junit.jupiter:junit-jupiter-api:5.+'
19+
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.+'
1320
}
1421

1522
test {
@@ -22,4 +29,8 @@ test {
2229
reports {
2330
html.enabled = true
2431
}
25-
}
32+
}
33+
34+
application {
35+
mainClassName = "tv.codely.context.video.module.video.infrastructure.VideoPublisherCliController"
36+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package tv.codely.context.notification.module.push.application.create;
2+
3+
import tv.codely.context.video.module.video.domain.VideoPublished;
4+
import tv.codely.shared.application.DomainEventSubscriber;
5+
6+
public class SendPushToSubscribersOnVideoPublished implements DomainEventSubscriber<VideoPublished> {
7+
@Override
8+
public Class<VideoPublished> subscribedTo() {
9+
return VideoPublished.class;
10+
}
11+
12+
@Override
13+
public void consume(VideoPublished event) {
14+
System.out.println(
15+
String.format(
16+
"Hey! There is a new video with title <%s> and description <%s>",
17+
event.title(),
18+
event.description()
19+
)
20+
);
21+
}
22+
}

src/main/java/tv/codely/context/notification/module/push/application/find/.gitkeep

Whitespace-only changes.

src/main/java/tv/codely/context/notification/module/push/domain/.gitkeep

Whitespace-only changes.

src/main/java/tv/codely/context/notification/module/push/infrastructure/.gitkeep

Whitespace-only changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package tv.codely.context.video.module.video.application.publish;
2+
3+
import tv.codely.context.video.module.video.domain.Video;
4+
import tv.codely.context.video.module.video.domain.VideoDescription;
5+
import tv.codely.context.video.module.video.domain.VideoTitle;
6+
import tv.codely.shared.domain.EventBus;
7+
8+
public final class VideoPublisher {
9+
private final EventBus eventBus;
10+
11+
public VideoPublisher(EventBus eventBus) {
12+
this.eventBus = eventBus;
13+
}
14+
15+
public void publish(String rawTitle, String rawDescription) {
16+
final var title = new VideoTitle(rawTitle);
17+
final var description = new VideoDescription(rawDescription);
18+
19+
final var video = Video.publish(title, description);
20+
21+
eventBus.publish(video.pullDomainEvents());
22+
}
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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 VideoTitle title;
7+
private final VideoDescription description;
8+
9+
private Video(VideoTitle title, VideoDescription description) {
10+
this.title = title;
11+
this.description = description;
12+
}
13+
14+
public static Video publish(VideoTitle title, VideoDescription description) {
15+
var video = new Video(title, description);
16+
17+
var videoCreated = new VideoPublished(title.value(), description.value());
18+
19+
video.record(videoCreated);
20+
21+
return video;
22+
}
23+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package tv.codely.context.video.module.video.domain;
2+
3+
public final class VideoDescription {
4+
private final String value;
5+
6+
public VideoDescription(final String value) {
7+
this.value = value;
8+
}
9+
10+
public String value() {
11+
return value;
12+
}
13+
14+
@Override
15+
public boolean equals(Object o) {
16+
if (this == o) return true;
17+
if (o == null || getClass() != o.getClass()) return false;
18+
19+
VideoDescription that = (VideoDescription) o;
20+
21+
return value.equals(that.value);
22+
}
23+
24+
@Override
25+
public int hashCode() {
26+
return value.hashCode();
27+
}
28+
}

0 commit comments

Comments
 (0)