diff --git a/etc/http/publish_domain_events.http b/etc/http/publish_domain_events.http index 9b512e6b..309c2fd7 100644 --- a/etc/http/publish_domain_events.http +++ b/etc/http/publish_domain_events.http @@ -9,7 +9,7 @@ Content-Type: application/json "type": "course.created", "occurred_on": "2023-11-14 10:00:00", "attributes": { - "id": "9bd0c98a-92cc-4a56-a5a1-7d40839ddc83", + "id": "c3a11f1d-512e-420b-aeae-e687a3c449aa", "name": "Demo course", "duration": "2 days" } @@ -31,8 +31,29 @@ Content-Type: application/json "type": "course.renamed", "occurred_on": "2023-11-14 10:00:00", "attributes": { - "id": "9bd0c98a-92cc-4a56-a5a1-7d40839ddc83", - "name": "heeey 22222" + "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": { diff --git a/src/backoffice/main/tv/codely/backoffice/courses/application/create/BackofficeCourseCreator.java b/src/backoffice/main/tv/codely/backoffice/courses/application/create/BackofficeCourseCreator.java index f129d16a..496b8cb5 100644 --- a/src/backoffice/main/tv/codely/backoffice/courses/application/create/BackofficeCourseCreator.java +++ b/src/backoffice/main/tv/codely/backoffice/courses/application/create/BackofficeCourseCreator.java @@ -13,6 +13,8 @@ public BackofficeCourseCreator(BackofficeCourseRepository repository) { } public void create(String id, String name, String duration) { - this.repository.save(new BackofficeCourse(id, name, duration)); + if (this.repository.search(id).isEmpty()) { + this.repository.save(new BackofficeCourse(id, name, duration)); + } } } diff --git a/src/backoffice/main/tv/codely/backoffice/courses/infrastructure/persistence/ElasticsearchBackofficeCourseRepository.java b/src/backoffice/main/tv/codely/backoffice/courses/infrastructure/persistence/ElasticsearchBackofficeCourseRepository.java index 1206e8fb..c97dd85d 100644 --- a/src/backoffice/main/tv/codely/backoffice/courses/infrastructure/persistence/ElasticsearchBackofficeCourseRepository.java +++ b/src/backoffice/main/tv/codely/backoffice/courses/infrastructure/persistence/ElasticsearchBackofficeCourseRepository.java @@ -14,14 +14,14 @@ @Primary @Service public final class ElasticsearchBackofficeCourseRepository extends ElasticsearchRepository implements BackofficeCourseRepository { - public ElasticsearchBackofficeCourseRepository(ElasticsearchClient client) { - super(client); - } + public ElasticsearchBackofficeCourseRepository(ElasticsearchClient client) { + super(client); + } - @Override - public void save(BackofficeCourse course) { - persist(course.id(), course.toPrimitives()); - } + @Override + public void save(BackofficeCourse course) { + persist(course.id(), course.toPrimitives()); + } @Override public Optional search(String id) { @@ -29,17 +29,17 @@ public Optional search(String id) { } @Override - public List searchAll() { - return searchAllInElastic(BackofficeCourse::fromPrimitives); - } - - @Override - public List matching(Criteria criteria) { - return searchByCriteria(criteria, BackofficeCourse::fromPrimitives); - } - - @Override - protected String moduleName() { - return "courses"; - } + public List searchAll() { + return searchAllInElastic(BackofficeCourse::fromPrimitives); + } + + @Override + public List matching(Criteria criteria) { + return searchByCriteria(criteria, BackofficeCourse::fromPrimitives); + } + + @Override + protected String moduleName() { + return "courses"; + } } diff --git a/src/shared/main/tv/codely/shared/infrastructure/bus/event/rabbitmq/RabbitMqDomainEventsConsumer.java b/src/shared/main/tv/codely/shared/infrastructure/bus/event/rabbitmq/RabbitMqDomainEventsConsumer.java index 1311278a..d1620f3f 100644 --- a/src/shared/main/tv/codely/shared/infrastructure/bus/event/rabbitmq/RabbitMqDomainEventsConsumer.java +++ b/src/shared/main/tv/codely/shared/infrastructure/bus/event/rabbitmq/RabbitMqDomainEventsConsumer.java @@ -70,8 +70,12 @@ public void consumer(Message message) throws Exception { try { subscriberOnMethod.invoke(subscriber, domainEvent); + + System.out.println("ACK: Consumed correctly!"); } catch (Exception error) { - handleConsumptionError(message, queue); + System.out.println("Error consuming"); + + handleConsumptionError(message, queue); } }