generated from CodelyTV/java-basic-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add endpoint to publish raw domain events #86
Draft
rgomezcasas
wants to merge
5
commits into
main
Choose a base branch
from
add-events
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
27d8146
feat: add endpoint to publish raw domain events
rgomezcasas ec05c6c
feat: add use case to rename a course
rgomezcasas 4f0ff47
fix: rabbitmq event bus
rgomezcasas b268158
feat: improve event consumption
rgomezcasas 4d337d6
feat: add script to create infinite courses
rgomezcasas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 @@ | ||
spring.main.allow-bean-definition-overriding=true |
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
Empty file.
18 changes: 18 additions & 0 deletions
18
apps/main/tv/codely/apps/backoffice/backend/command/ConsumeRabbitMqDomainEventsCommand.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,18 @@ | ||
package tv.codely.apps.backoffice.backend.command; | ||
|
||
import tv.codely.shared.infrastructure.bus.event.rabbitmq.RabbitMqDomainEventsConsumer; | ||
import tv.codely.shared.infrastructure.cli.ConsoleCommand; | ||
|
||
public final class ConsumeRabbitMqDomainEventsCommand extends ConsoleCommand { | ||
|
||
private final RabbitMqDomainEventsConsumer consumer; | ||
|
||
public ConsumeRabbitMqDomainEventsCommand(RabbitMqDomainEventsConsumer consumer) { | ||
this.consumer = consumer; | ||
} | ||
|
||
@Override | ||
public void execute(String[] args) { | ||
consumer.consume("backoffice"); | ||
} | ||
} |
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
53 changes: 53 additions & 0 deletions
53
apps/main/tv/codely/apps/mooc/backend/controller/playground/DomainEventPostController.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,53 @@ | ||
package tv.codely.apps.mooc.backend.controller.playground; | ||
|
||
import org.springframework.amqp.core.Message; | ||
import org.springframework.amqp.core.MessagePropertiesBuilder; | ||
import org.springframework.amqp.rabbit.core.RabbitTemplate; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import tv.codely.shared.domain.Utils; | ||
|
||
@RestController | ||
record DomainEventPostController(RabbitTemplate rabbitTemplate) { | ||
@PostMapping(value = "/domain-events") | ||
public ResponseEntity<String> index(@RequestBody Request request) { | ||
System.out.println(request.eventName()); | ||
|
||
var serializedEvent = Utils.jsonEncode(request.eventRaw()); | ||
|
||
Message message = new Message( | ||
serializedEvent.getBytes(), | ||
MessagePropertiesBuilder.newInstance().setContentEncoding("utf-8").setContentType("application/json").build() | ||
); | ||
|
||
rabbitTemplate.send("domain_events", request.eventName(), message); | ||
|
||
return new ResponseEntity<>(HttpStatus.CREATED); | ||
} | ||
} | ||
|
||
final class Request { | ||
|
||
private String eventName; | ||
private Object eventRaw; | ||
|
||
public void setEventName(String eventName) { | ||
this.eventName = eventName; | ||
} | ||
|
||
public void setEventRaw(Object eventRaw) { | ||
this.eventRaw = eventRaw; | ||
} | ||
|
||
String eventName() { | ||
return eventName; | ||
} | ||
|
||
Object eventRaw() { | ||
return eventRaw; | ||
} | ||
} |
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
File renamed without changes.
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,62 @@ | ||
POST http://localhost:8030/domain-events | ||
Content-Type: application/json | ||
|
||
{ | ||
"eventName": "course.created", | ||
"eventRaw": { | ||
"data": { | ||
"id": "{{$random.uuid}}", | ||
"type": "course.created", | ||
"occurred_on": "2023-11-14 10:00:00", | ||
"attributes": { | ||
"id": "c3a11f1d-512e-420b-aeae-e687a3c449aa", | ||
"name": "Demo course", | ||
"duration": "2 days" | ||
} | ||
}, | ||
"meta": { | ||
} | ||
} | ||
} | ||
|
||
### | ||
POST http://localhost:8030/domain-events | ||
Content-Type: application/json | ||
|
||
{ | ||
"eventName": "course.renamed", | ||
"eventRaw": { | ||
"data": { | ||
"id": "{{$random.uuid}}", | ||
"type": "course.renamed", | ||
"occurred_on": "2023-11-14 10:00:00", | ||
"attributes": { | ||
"id": "7b081a3e-f90e-4efe-a3a5-81e853e89c8b", | ||
"name": "Este es el nombre bueno" | ||
} | ||
}, | ||
"meta": { | ||
} | ||
} | ||
} | ||
|
||
### | ||
POST http://localhost:8030/domain-events | ||
Content-Type: application/json | ||
|
||
{ | ||
"eventName": "course.renamed", | ||
"eventRaw": { | ||
"data": { | ||
"id": "{{$random.uuid}}", | ||
"type": "course.renamed", | ||
"occurred_on": "2022-11-14 10:00:00", | ||
"attributes": { | ||
"id": "7b081a3e-f90e-4efe-a3a5-81e853e89c8b", | ||
"name": "Este es el nombre malo" | ||
} | ||
}, | ||
"meta": { | ||
} | ||
} | ||
} |
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,33 @@ | ||
function create_course() { | ||
eventId=$(uuidgen) | ||
courseId=$(uuidgen) | ||
courseName=$(shuf -n3 /usr/share/dict/words | xargs) | ||
courseDuration=$((1 + RANDOM % 1000)) | ||
|
||
curl -X POST --location "http://localhost:8030/domain-events" \ | ||
-H "Content-Type: application/json" \ | ||
-d '{ | ||
"eventName": "course.created", | ||
"eventRaw": { | ||
"data": { | ||
"id": "'"$eventId"'", | ||
"type": "course.created", | ||
"occurred_on": "2023-11-14 10:00:00", | ||
"attributes": { | ||
"id": "'"$courseId"'", | ||
"name": "'"$courseName"'", | ||
"duration": "'"$courseDuration"' days" | ||
} | ||
}, | ||
"meta": { | ||
} | ||
} | ||
}' | ||
|
||
echo "Created: $courseName" | ||
} | ||
|
||
while true; do | ||
create_course & | ||
sleep 0.001 | ||
done |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a demo