diff --git a/Makefile b/Makefile index c312ce16..4855cd12 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ all: build start: - @docker-compose -f docker-compose.ci.yml up -d + @docker compose -f docker-compose.ci.yml up -d build: @./gradlew build --warning-mode all diff --git a/apps/main/resources/application.properties b/apps/main/resources/application.properties new file mode 100644 index 00000000..e439ebd8 --- /dev/null +++ b/apps/main/resources/application.properties @@ -0,0 +1 @@ +spring.main.allow-bean-definition-overriding=true diff --git a/apps/main/resources/backoffice_frontend/templates/pages/courses/partials/list_courses.ftl b/apps/main/resources/backoffice_frontend/templates/pages/courses/partials/list_courses.ftl index e81af3c3..aa64bee9 100644 --- a/apps/main/resources/backoffice_frontend/templates/pages/courses/partials/list_courses.ftl +++ b/apps/main/resources/backoffice_frontend/templates/pages/courses/partials/list_courses.ftl @@ -142,12 +142,12 @@ const urlParts = inputs.map(input => input.name + "=" + input.value); - const url = "http://localhost:8091/courses?" + urlParts.join("&"); + const url = "http://localhost:8040/courses?" + urlParts.join("&"); addCoursesList(url); } diff --git a/apps/main/tv/codely/apps/backoffice/backend/BackofficeBackendApplication.java b/apps/main/tv/codely/apps/backoffice/backend/BackofficeBackendApplication.java index 873122f3..0a9374e3 100644 --- a/apps/main/tv/codely/apps/backoffice/backend/BackofficeBackendApplication.java +++ b/apps/main/tv/codely/apps/backoffice/backend/BackofficeBackendApplication.java @@ -7,6 +7,7 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.FilterType; +import tv.codely.apps.backoffice.backend.command.ConsumeRabbitMqDomainEventsCommand; import tv.codely.shared.domain.Service; @SpringBootApplication(exclude = HibernateJpaAutoConfiguration.class) @@ -17,8 +18,10 @@ public class BackofficeBackendApplication { public static HashMap> commands() { - return new HashMap>() { - {} + return new HashMap<>() { + { + put("domain-events:rabbitmq:consume", ConsumeRabbitMqDomainEventsCommand.class); + } }; } } diff --git a/apps/main/tv/codely/apps/backoffice/backend/command/.gitkeep b/apps/main/tv/codely/apps/backoffice/backend/command/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/apps/main/tv/codely/apps/backoffice/backend/command/ConsumeRabbitMqDomainEventsCommand.java b/apps/main/tv/codely/apps/backoffice/backend/command/ConsumeRabbitMqDomainEventsCommand.java new file mode 100644 index 00000000..018972f4 --- /dev/null +++ b/apps/main/tv/codely/apps/backoffice/backend/command/ConsumeRabbitMqDomainEventsCommand.java @@ -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"); + } +} diff --git a/apps/main/tv/codely/apps/backoffice/frontend/config/BackofficeFrontendWebConfig.java b/apps/main/tv/codely/apps/backoffice/frontend/config/BackofficeFrontendWebConfig.java index 31405d6f..62749d15 100644 --- a/apps/main/tv/codely/apps/backoffice/frontend/config/BackofficeFrontendWebConfig.java +++ b/apps/main/tv/codely/apps/backoffice/frontend/config/BackofficeFrontendWebConfig.java @@ -1,7 +1,9 @@ package tv.codely.apps.backoffice.frontend.config; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; @@ -10,6 +12,10 @@ import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver; +import tv.codely.shared.infrastructure.bus.event.mysql.MySqlEventBus; +import tv.codely.shared.infrastructure.bus.event.rabbitmq.RabbitMqEventBus; +import tv.codely.shared.infrastructure.bus.event.rabbitmq.RabbitMqPublisher; + @Configuration @EnableWebMvc public class BackofficeFrontendWebConfig implements WebMvcConfigurer { @@ -43,4 +49,13 @@ public FreeMarkerConfigurer freeMarkerConfigurer() { return configurer; } + + @Primary + @Bean + public RabbitMqEventBus rabbitMqEventBus( + RabbitMqPublisher publisher, + @Qualifier("backofficeMysqlEventBus") MySqlEventBus failoverPublisher + ) { + return new RabbitMqEventBus(publisher, failoverPublisher); + } } diff --git a/apps/main/tv/codely/apps/mooc/backend/command/ConsumeRabbitMqDomainEventsCommand.java b/apps/main/tv/codely/apps/mooc/backend/command/ConsumeRabbitMqDomainEventsCommand.java index 993dcd5b..ce5d7bdc 100644 --- a/apps/main/tv/codely/apps/mooc/backend/command/ConsumeRabbitMqDomainEventsCommand.java +++ b/apps/main/tv/codely/apps/mooc/backend/command/ConsumeRabbitMqDomainEventsCommand.java @@ -13,6 +13,6 @@ public ConsumeRabbitMqDomainEventsCommand(RabbitMqDomainEventsConsumer consumer) @Override public void execute(String[] args) { - consumer.consume(); + consumer.consume("mooc"); } } diff --git a/apps/main/tv/codely/apps/mooc/backend/config/MoocBackendServerConfiguration.java b/apps/main/tv/codely/apps/mooc/backend/config/MoocBackendServerConfiguration.java index 9974cddc..3041e7bd 100644 --- a/apps/main/tv/codely/apps/mooc/backend/config/MoocBackendServerConfiguration.java +++ b/apps/main/tv/codely/apps/mooc/backend/config/MoocBackendServerConfiguration.java @@ -1,5 +1,7 @@ package tv.codely.apps.mooc.backend.config; +import java.util.Optional; + import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -10,9 +12,9 @@ @Configuration public class MoocBackendServerConfiguration { - private final RequestMappingHandlerMapping mapping; + private final Optional mapping; - public MoocBackendServerConfiguration(RequestMappingHandlerMapping mapping) { + public MoocBackendServerConfiguration(Optional mapping) { this.mapping = mapping; } @@ -20,7 +22,7 @@ public MoocBackendServerConfiguration(RequestMappingHandlerMapping mapping) { public FilterRegistrationBean apiExceptionMiddleware() { FilterRegistrationBean registrationBean = new FilterRegistrationBean<>(); - registrationBean.setFilter(new ApiExceptionMiddleware(mapping)); + mapping.ifPresent(map -> registrationBean.setFilter(new ApiExceptionMiddleware(map))); return registrationBean; } diff --git a/docker-compose.yml b/docker-compose.yml index 2dd4b00c..216bacd5 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -51,12 +51,29 @@ services: volumes: - .:/app:delegated - backoffice_backend_gradle_cache:/app/.gradle + - backoffice_backend_build:/app/build depends_on: - shared_mysql - shared_rabbitmq - backoffice_elasticsearch command: ["./gradlew", "bootRun", "--args", "backoffice_backend server"] + backoffice_backend_consumers_java: + container_name: codely-java_ddd_example-backoffice_backend_consumers + build: + context: . + dockerfile: Dockerfile + restart: unless-stopped + volumes: + - .:/app:delegated + - backoffice_consumers_gradle_cache:/app/.gradle + - backoffice_consumers_build:/app/build + depends_on: + - shared_mysql + - shared_rabbitmq + - backoffice_elasticsearch + command: ["./gradlew", "bootRun", "--args", "backoffice_backend domain-events:rabbitmq:consume"] + backoffice_frontend_server_java: container_name: codely-java_ddd_example-backoffice_frontend_server build: @@ -68,6 +85,7 @@ services: volumes: - .:/app:delegated - backoffice_frontend_gradle_cache:/app/.gradle + - backoffice_frontend_build:/app/build depends_on: - shared_mysql - shared_rabbitmq @@ -85,13 +103,37 @@ services: volumes: - .:/app:delegated - mooc_backend_gradle_cache:/app/.gradle + - mooc_backend_build:/app/build depends_on: - shared_mysql - shared_rabbitmq - backoffice_elasticsearch command: ["./gradlew", "bootRun", "--args", "mooc_backend server"] + mooc_backend_consumers_java: + container_name: codely-java_ddd_example-mooc_backend_consumers + build: + context: . + dockerfile: Dockerfile + restart: unless-stopped + volumes: + - .:/app:delegated + - mooc_consumers_gradle_cache:/app/.gradle + - mooc_consumers_build:/app/build + depends_on: + - shared_mysql + - shared_rabbitmq + - backoffice_elasticsearch + command: ["./gradlew", "bootRun", "--args", "mooc_backend domain-events:rabbitmq:consume"] + volumes: backoffice_backend_gradle_cache: + backoffice_backend_build: + backoffice_consumers_gradle_cache: + backoffice_consumers_build: backoffice_frontend_gradle_cache: + backoffice_frontend_build: mooc_backend_gradle_cache: + mooc_backend_build: + mooc_consumers_gradle_cache: + mooc_consumers_build: diff --git a/etc/http/publish_domain_events.http b/etc/http/publish_domain_events.http index d6a19315..9b512e6b 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": "{{$random.uuid}}", + "id": "9bd0c98a-92cc-4a56-a5a1-7d40839ddc83", "name": "Demo course", "duration": "2 days" } @@ -18,3 +18,24 @@ Content-Type: application/json } } } + +### +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": "9bd0c98a-92cc-4a56-a5a1-7d40839ddc83", + "name": "heeey 22222" + } + }, + "meta": { + } + } +} diff --git a/src/backoffice/main/tv/codely/backoffice/courses/application/rename/BackofficeCourseRenamer.java b/src/backoffice/main/tv/codely/backoffice/courses/application/rename/BackofficeCourseRenamer.java index 35a3034a..e50c42f4 100644 --- a/src/backoffice/main/tv/codely/backoffice/courses/application/rename/BackofficeCourseRenamer.java +++ b/src/backoffice/main/tv/codely/backoffice/courses/application/rename/BackofficeCourseRenamer.java @@ -1,5 +1,6 @@ package tv.codely.backoffice.courses.application.rename; +import tv.codely.backoffice.courses.domain.BackofficeCourseNotFound; import tv.codely.backoffice.courses.domain.BackofficeCourseRepository; import tv.codely.shared.domain.Service; @@ -13,10 +14,13 @@ public BackofficeCourseRenamer(BackofficeCourseRepository repository) { public void rename(String id, String name) { this.repository.search(id) - .ifPresent(course -> { - course.rename(name); + .ifPresentOrElse(course -> { + course.rename(name); - this.repository.save(course); - }); + this.repository.save(course); + }, + () -> { + throw new BackofficeCourseNotFound(id); + }); } } diff --git a/src/backoffice/main/tv/codely/backoffice/courses/application/rename/RenameBackofficeCourseOnCourseRenamed.java b/src/backoffice/main/tv/codely/backoffice/courses/application/rename/RenameBackofficeCourseOnCourseRenamed.java index d9a05491..c92e48d3 100644 --- a/src/backoffice/main/tv/codely/backoffice/courses/application/rename/RenameBackofficeCourseOnCourseRenamed.java +++ b/src/backoffice/main/tv/codely/backoffice/courses/application/rename/RenameBackofficeCourseOnCourseRenamed.java @@ -3,11 +3,10 @@ import org.springframework.context.event.EventListener; import tv.codely.shared.domain.Service; import tv.codely.shared.domain.bus.event.DomainEventSubscriber; -import tv.codely.shared.domain.course.CourseCreatedDomainEvent; import tv.codely.shared.domain.course.CourseRenamedDomainEvent; @Service -@DomainEventSubscriber({CourseCreatedDomainEvent.class}) +@DomainEventSubscriber({CourseRenamedDomainEvent.class}) public final class RenameBackofficeCourseOnCourseRenamed { private final BackofficeCourseRenamer renamer; diff --git a/src/backoffice/main/tv/codely/backoffice/courses/domain/BackofficeCourseNotFound.java b/src/backoffice/main/tv/codely/backoffice/courses/domain/BackofficeCourseNotFound.java new file mode 100644 index 00000000..f5596ffa --- /dev/null +++ b/src/backoffice/main/tv/codely/backoffice/courses/domain/BackofficeCourseNotFound.java @@ -0,0 +1,7 @@ +package tv.codely.backoffice.courses.domain; + +public class BackofficeCourseNotFound extends RuntimeException { + public BackofficeCourseNotFound(String id) { + super(String.format("The course <%s> doesn't exist", id)); + } +} diff --git a/src/backoffice/main/tv/codely/backoffice/shared/infrastructure/persistence/BackofficeMySqlEventBusConfiguration.java b/src/backoffice/main/tv/codely/backoffice/shared/infrastructure/persistence/BackofficeMySqlEventBusConfiguration.java index 4704f7b3..1113298e 100644 --- a/src/backoffice/main/tv/codely/backoffice/shared/infrastructure/persistence/BackofficeMySqlEventBusConfiguration.java +++ b/src/backoffice/main/tv/codely/backoffice/shared/infrastructure/persistence/BackofficeMySqlEventBusConfiguration.java @@ -4,6 +4,7 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; import tv.codely.shared.infrastructure.bus.event.DomainEventsInformation; import tv.codely.shared.infrastructure.bus.event.mysql.MySqlDomainEventsConsumer; import tv.codely.shared.infrastructure.bus.event.mysql.MySqlEventBus; diff --git a/src/mooc/test/tv/codely/mooc/shared/infrastructure/bus/event/rabbitmq/RabbitMqEventBusShould.java b/src/mooc/test/tv/codely/mooc/shared/infrastructure/bus/event/rabbitmq/RabbitMqEventBusShould.java index e5592563..70c8de26 100644 --- a/src/mooc/test/tv/codely/mooc/shared/infrastructure/bus/event/rabbitmq/RabbitMqEventBusShould.java +++ b/src/mooc/test/tv/codely/mooc/shared/infrastructure/bus/event/rabbitmq/RabbitMqEventBusShould.java @@ -46,7 +46,7 @@ void publish_and_consume_domain_events_from_rabbitmq() throws Exception { eventBus.publish(Collections.singletonList(domainEvent)); - consumer.consume(); + consumer.consume("mooc"); eventually(() -> assertTrue(subscriber.hasBeenExecuted)); } diff --git a/src/shared/main/tv/codely/shared/domain/course/CourseRenamedDomainEvent.java b/src/shared/main/tv/codely/shared/domain/course/CourseRenamedDomainEvent.java index b85592b6..2fb40972 100644 --- a/src/shared/main/tv/codely/shared/domain/course/CourseRenamedDomainEvent.java +++ b/src/shared/main/tv/codely/shared/domain/course/CourseRenamedDomainEvent.java @@ -34,7 +34,7 @@ public CourseRenamedDomainEvent( @Override public String eventName() { - return "course.created"; + return "course.renamed"; } @Override diff --git a/src/shared/main/tv/codely/shared/infrastructure/bus/event/DomainEventSubscribersInformation.java b/src/shared/main/tv/codely/shared/infrastructure/bus/event/DomainEventSubscribersInformation.java index e7f5b923..88556f11 100644 --- a/src/shared/main/tv/codely/shared/infrastructure/bus/event/DomainEventSubscribersInformation.java +++ b/src/shared/main/tv/codely/shared/infrastructure/bus/event/DomainEventSubscribersInformation.java @@ -11,43 +11,44 @@ @Service public final class DomainEventSubscribersInformation { - HashMap, DomainEventSubscriberInformation> information; - - public DomainEventSubscribersInformation(HashMap, DomainEventSubscriberInformation> information) { - this.information = information; - } - - public DomainEventSubscribersInformation() { - this(scanDomainEventSubscribers()); - } - - private static HashMap, DomainEventSubscriberInformation> scanDomainEventSubscribers() { - Reflections reflections = new Reflections("tv.codely"); - Set> subscribers = reflections.getTypesAnnotatedWith(DomainEventSubscriber.class); - - HashMap, DomainEventSubscriberInformation> subscribersInformation = new HashMap<>(); - - for (Class subscriberClass : subscribers) { - DomainEventSubscriber annotation = subscriberClass.getAnnotation(DomainEventSubscriber.class); - - subscribersInformation.put( - subscriberClass, - new DomainEventSubscriberInformation(subscriberClass, Arrays.asList(annotation.value())) - ); - } - - return subscribersInformation; - } - - public Collection all() { - return information.values(); - } - - public String[] rabbitMqFormattedNames() { - return information.values() - .stream() - .map(DomainEventSubscriberInformation::formatRabbitMqQueueName) - .distinct() - .toArray(String[]::new); - } + HashMap, DomainEventSubscriberInformation> information; + + public DomainEventSubscribersInformation(HashMap, DomainEventSubscriberInformation> information) { + this.information = information; + } + + public DomainEventSubscribersInformation() { + this(scanDomainEventSubscribers()); + } + + private static HashMap, DomainEventSubscriberInformation> scanDomainEventSubscribers() { + Reflections reflections = new Reflections("tv.codely"); + Set> subscribers = reflections.getTypesAnnotatedWith(DomainEventSubscriber.class); + + HashMap, DomainEventSubscriberInformation> subscribersInformation = new HashMap<>(); + + for (Class subscriberClass : subscribers) { + DomainEventSubscriber annotation = subscriberClass.getAnnotation(DomainEventSubscriber.class); + + subscribersInformation.put( + subscriberClass, + new DomainEventSubscriberInformation(subscriberClass, Arrays.asList(annotation.value())) + ); + } + + return subscribersInformation; + } + + public Collection all() { + return information.values(); + } + + public String[] rabbitMqFormattedNamesFor(String contextName) { + return information.values() + .stream() + .map(DomainEventSubscriberInformation::formatRabbitMqQueueName) + .distinct() + .filter(queueName -> queueName.contains("." + contextName + ".")) + .toArray(String[]::new); + } } 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 f613ecc2..1311278a 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 @@ -13,7 +13,6 @@ import tv.codely.shared.infrastructure.bus.event.DomainEventJsonDeserializer; import tv.codely.shared.infrastructure.bus.event.DomainEventSubscribersInformation; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; @@ -21,13 +20,14 @@ @Service public final class RabbitMqDomainEventsConsumer { private final String CONSUMER_NAME = "domain_events_consumer"; - private final int MAX_RETRIES = 2; + private final int MAX_RETRIES = 10; private final DomainEventJsonDeserializer deserializer; private final ApplicationContext context; private final RabbitMqPublisher publisher; private final HashMap domainEventSubscribers = new HashMap<>(); RabbitListenerEndpointRegistry registry; private DomainEventSubscribersInformation information; + private String contextName; public RabbitMqDomainEventsConsumer( RabbitListenerEndpointRegistry registry, @@ -43,12 +43,14 @@ public RabbitMqDomainEventsConsumer( this.publisher = publisher; } - public void consume() { + public void consume(String contextName) { + this.contextName = contextName; + AbstractMessageListenerContainer container = (AbstractMessageListenerContainer) registry.getListenerContainer( CONSUMER_NAME ); - container.addQueueNames(information.rabbitMqFormattedNames()); + container.addQueueNames(information.rabbitMqFormattedNamesFor(contextName)); container.start(); } @@ -68,12 +70,6 @@ public void consumer(Message message) throws Exception { try { subscriberOnMethod.invoke(subscriber, domainEvent); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException error) { - throw new Exception(String.format( - "The subscriber <%s> should implement a method `on` listening the domain event <%s>", - queue, - domainEvent.eventName() - )); } catch (Exception error) { handleConsumptionError(message, queue); } @@ -92,10 +88,14 @@ private void handleConsumptionError(Message message, String queue) { } private void sendToRetry(Message message, String queue) { + System.out.println("SENDING TO RETRY: " + contextName + " - " + queue); + sendMessageTo(RabbitMqExchangeNameFormatter.retry("domain_events"), message, queue); } private void sendToDeadLetter(Message message, String queue) { + System.out.println("SENDING TO DEAD LETTER: " + contextName + " - " + queue); + sendMessageTo(RabbitMqExchangeNameFormatter.deadLetter("domain_events"), message, queue); } diff --git a/src/shared/main/tv/codely/shared/infrastructure/bus/event/rabbitmq/RabbitMqEventBus.java b/src/shared/main/tv/codely/shared/infrastructure/bus/event/rabbitmq/RabbitMqEventBus.java index 47d1738f..2bad6fd2 100644 --- a/src/shared/main/tv/codely/shared/infrastructure/bus/event/rabbitmq/RabbitMqEventBus.java +++ b/src/shared/main/tv/codely/shared/infrastructure/bus/event/rabbitmq/RabbitMqEventBus.java @@ -1,6 +1,8 @@ package tv.codely.shared.infrastructure.bus.event.rabbitmq; import org.springframework.amqp.AmqpException; +import org.springframework.context.annotation.Primary; +import tv.codely.shared.domain.Service; import tv.codely.shared.domain.bus.event.DomainEvent; import tv.codely.shared.domain.bus.event.EventBus; import tv.codely.shared.infrastructure.bus.event.mysql.MySqlEventBus; @@ -8,27 +10,29 @@ import java.util.Collections; import java.util.List; +@Primary +@Service public class RabbitMqEventBus implements EventBus { - private final RabbitMqPublisher publisher; - private final MySqlEventBus failoverPublisher; - private final String exchangeName; + private final RabbitMqPublisher publisher; + private final MySqlEventBus failoverPublisher; + private final String exchangeName; - public RabbitMqEventBus(RabbitMqPublisher publisher, MySqlEventBus failoverPublisher) { - this.publisher = publisher; - this.failoverPublisher = failoverPublisher; - this.exchangeName = "domain_events"; - } + public RabbitMqEventBus(RabbitMqPublisher publisher, MySqlEventBus failoverPublisher) { + this.publisher = publisher; + this.failoverPublisher = failoverPublisher; + this.exchangeName = "domain_events"; + } - @Override - public void publish(List events) { - events.forEach(this::publish); - } + @Override + public void publish(List events) { + events.forEach(this::publish); + } - private void publish(DomainEvent domainEvent) { - try { - this.publisher.publish(domainEvent, exchangeName); - } catch (AmqpException error) { - failoverPublisher.publish(Collections.singletonList(domainEvent)); - } - } + private void publish(DomainEvent domainEvent) { + try { + this.publisher.publish(domainEvent, exchangeName); + } catch (AmqpException error) { + failoverPublisher.publish(Collections.singletonList(domainEvent)); + } + } } diff --git a/src/shared/main/tv/codely/shared/infrastructure/bus/event/rabbitmq/RabbitMqEventBusConfiguration.java b/src/shared/main/tv/codely/shared/infrastructure/bus/event/rabbitmq/RabbitMqEventBusConfiguration.java index 4fe9688a..f95e1888 100644 --- a/src/shared/main/tv/codely/shared/infrastructure/bus/event/rabbitmq/RabbitMqEventBusConfiguration.java +++ b/src/shared/main/tv/codely/shared/infrastructure/bus/event/rabbitmq/RabbitMqEventBusConfiguration.java @@ -128,7 +128,7 @@ private HashMap retryQueueArguments(TopicExchange exchange, Stri return new HashMap() {{ put("x-dead-letter-exchange", exchange.getName()); put("x-dead-letter-routing-key", routingKey); - put("x-message-ttl", 1000); + put("x-message-ttl", 3000); }}; } } diff --git a/src/shared/main/tv/codely/shared/infrastructure/bus/event/spring/SpringApplicationEventBus.java b/src/shared/main/tv/codely/shared/infrastructure/bus/event/spring/SpringApplicationEventBus.java index 0b2a16a4..56a6205e 100644 --- a/src/shared/main/tv/codely/shared/infrastructure/bus/event/spring/SpringApplicationEventBus.java +++ b/src/shared/main/tv/codely/shared/infrastructure/bus/event/spring/SpringApplicationEventBus.java @@ -1,14 +1,12 @@ package tv.codely.shared.infrastructure.bus.event.spring; import org.springframework.context.ApplicationEventPublisher; -import org.springframework.context.annotation.Primary; import tv.codely.shared.domain.Service; import tv.codely.shared.domain.bus.event.DomainEvent; import tv.codely.shared.domain.bus.event.EventBus; import java.util.List; -@Primary @Service public class SpringApplicationEventBus implements EventBus { private final ApplicationEventPublisher publisher; diff --git a/src/shared/main/tv/codely/shared/infrastructure/cli/ConsoleCommand.java b/src/shared/main/tv/codely/shared/infrastructure/cli/ConsoleCommand.java index 45468089..dd90a889 100644 --- a/src/shared/main/tv/codely/shared/infrastructure/cli/ConsoleCommand.java +++ b/src/shared/main/tv/codely/shared/infrastructure/cli/ConsoleCommand.java @@ -4,22 +4,22 @@ @Service public abstract class ConsoleCommand { - private static final String ANSI_RESET = "\u001B[0m"; - private static final String ANSI_RED = "\u001B[31m"; - private static final String ANSI_CYAN = "\u001B[36m"; - private static final String ANSI_GREEN = "\u001B[32m"; + private static final String ANSI_RESET = "\u001B[0m"; + private static final String ANSI_RED = "\u001B[31m"; + private static final String ANSI_CYAN = "\u001B[36m"; + private static final String ANSI_GREEN = "\u001B[32m"; - abstract public void execute(String[] args); + abstract public void execute(String[] args); - protected void log(String text) { - System.out.println(String.format("%s%s%s", ANSI_GREEN, text, ANSI_RESET)); - } + protected void log(String text) { + System.out.println(String.format("%s%s%s", ANSI_GREEN, text, ANSI_RESET)); + } - protected void info(String text) { - System.out.println(String.format("%s%s%s", ANSI_CYAN, text, ANSI_RESET)); - } + protected void info(String text) { + System.out.println(String.format("%s%s%s", ANSI_CYAN, text, ANSI_RESET)); + } - protected void error(String text) { - System.out.println(String.format("%s%s%s", ANSI_RED, text, ANSI_RESET)); - } + protected void error(String text) { + System.out.println(String.format("%s%s%s", ANSI_RED, text, ANSI_RESET)); + } }