Skip to content

Commit 4f0ff47

Browse files
committed
fix: rabbitmq event bus
1 parent ec05c6c commit 4f0ff47

23 files changed

Lines changed: 219 additions & 103 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
all: build
22

33
start:
4-
@docker-compose -f docker-compose.ci.yml up -d
4+
@docker compose -f docker-compose.ci.yml up -d
55

66
build:
77
@./gradlew build --warning-mode all
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
spring.main.allow-bean-definition-overriding=true

apps/main/resources/backoffice_frontend/templates/pages/courses/partials/list_courses.ftl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,12 @@
142142
143143
const urlParts = inputs.map(input => input.name + "=" + input.value);
144144
145-
const url = "http://localhost:8091/courses?" + urlParts.join("&");
145+
const url = "http://localhost:8040/courses?" + urlParts.join("&");
146146
147147
addCoursesList(url);
148148
}
149149
</script>
150150

151151
<script>
152-
addCoursesList("http://localhost:8091/courses");
152+
addCoursesList("http://localhost:8040/courses");
153153
</script>

apps/main/tv/codely/apps/backoffice/backend/BackofficeBackendApplication.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.springframework.context.annotation.ComponentScan;
88
import org.springframework.context.annotation.FilterType;
99

10+
import tv.codely.apps.backoffice.backend.command.ConsumeRabbitMqDomainEventsCommand;
1011
import tv.codely.shared.domain.Service;
1112

1213
@SpringBootApplication(exclude = HibernateJpaAutoConfiguration.class)
@@ -17,8 +18,10 @@
1718
public class BackofficeBackendApplication {
1819

1920
public static HashMap<String, Class<?>> commands() {
20-
return new HashMap<String, Class<?>>() {
21-
{}
21+
return new HashMap<>() {
22+
{
23+
put("domain-events:rabbitmq:consume", ConsumeRabbitMqDomainEventsCommand.class);
24+
}
2225
};
2326
}
2427
}

apps/main/tv/codely/apps/backoffice/backend/command/.gitkeep

Whitespace-only changes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package tv.codely.apps.backoffice.backend.command;
2+
3+
import tv.codely.shared.infrastructure.bus.event.rabbitmq.RabbitMqDomainEventsConsumer;
4+
import tv.codely.shared.infrastructure.cli.ConsoleCommand;
5+
6+
public final class ConsumeRabbitMqDomainEventsCommand extends ConsoleCommand {
7+
8+
private final RabbitMqDomainEventsConsumer consumer;
9+
10+
public ConsumeRabbitMqDomainEventsCommand(RabbitMqDomainEventsConsumer consumer) {
11+
this.consumer = consumer;
12+
}
13+
14+
@Override
15+
public void execute(String[] args) {
16+
consumer.consume("backoffice");
17+
}
18+
}

apps/main/tv/codely/apps/backoffice/frontend/config/BackofficeFrontendWebConfig.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package tv.codely.apps.backoffice.frontend.config;
22

3+
import org.springframework.beans.factory.annotation.Qualifier;
34
import org.springframework.context.annotation.Bean;
45
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.context.annotation.Primary;
57
import org.springframework.web.servlet.ViewResolver;
68
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
79
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
@@ -10,6 +12,10 @@
1012
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
1113
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
1214

15+
import tv.codely.shared.infrastructure.bus.event.mysql.MySqlEventBus;
16+
import tv.codely.shared.infrastructure.bus.event.rabbitmq.RabbitMqEventBus;
17+
import tv.codely.shared.infrastructure.bus.event.rabbitmq.RabbitMqPublisher;
18+
1319
@Configuration
1420
@EnableWebMvc
1521
public class BackofficeFrontendWebConfig implements WebMvcConfigurer {
@@ -43,4 +49,13 @@ public FreeMarkerConfigurer freeMarkerConfigurer() {
4349

4450
return configurer;
4551
}
52+
53+
@Primary
54+
@Bean
55+
public RabbitMqEventBus rabbitMqEventBus(
56+
RabbitMqPublisher publisher,
57+
@Qualifier("backofficeMysqlEventBus") MySqlEventBus failoverPublisher
58+
) {
59+
return new RabbitMqEventBus(publisher, failoverPublisher);
60+
}
4661
}

apps/main/tv/codely/apps/mooc/backend/command/ConsumeRabbitMqDomainEventsCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ public ConsumeRabbitMqDomainEventsCommand(RabbitMqDomainEventsConsumer consumer)
1313

1414
@Override
1515
public void execute(String[] args) {
16-
consumer.consume();
16+
consumer.consume("mooc");
1717
}
1818
}

apps/main/tv/codely/apps/mooc/backend/config/MoocBackendServerConfiguration.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package tv.codely.apps.mooc.backend.config;
22

3+
import java.util.Optional;
4+
35
import org.springframework.boot.web.servlet.FilterRegistrationBean;
46
import org.springframework.context.annotation.Bean;
57
import org.springframework.context.annotation.Configuration;
@@ -10,17 +12,17 @@
1012
@Configuration
1113
public class MoocBackendServerConfiguration {
1214

13-
private final RequestMappingHandlerMapping mapping;
15+
private final Optional<RequestMappingHandlerMapping> mapping;
1416

15-
public MoocBackendServerConfiguration(RequestMappingHandlerMapping mapping) {
17+
public MoocBackendServerConfiguration(Optional<RequestMappingHandlerMapping> mapping) {
1618
this.mapping = mapping;
1719
}
1820

1921
@Bean
2022
public FilterRegistrationBean<ApiExceptionMiddleware> apiExceptionMiddleware() {
2123
FilterRegistrationBean<ApiExceptionMiddleware> registrationBean = new FilterRegistrationBean<>();
2224

23-
registrationBean.setFilter(new ApiExceptionMiddleware(mapping));
25+
mapping.ifPresent(map -> registrationBean.setFilter(new ApiExceptionMiddleware(map)));
2426

2527
return registrationBean;
2628
}

docker-compose.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,29 @@ services:
5151
volumes:
5252
- .:/app:delegated
5353
- backoffice_backend_gradle_cache:/app/.gradle
54+
- backoffice_backend_build:/app/build
5455
depends_on:
5556
- shared_mysql
5657
- shared_rabbitmq
5758
- backoffice_elasticsearch
5859
command: ["./gradlew", "bootRun", "--args", "backoffice_backend server"]
5960

61+
backoffice_backend_consumers_java:
62+
container_name: codely-java_ddd_example-backoffice_backend_consumers
63+
build:
64+
context: .
65+
dockerfile: Dockerfile
66+
restart: unless-stopped
67+
volumes:
68+
- .:/app:delegated
69+
- backoffice_consumers_gradle_cache:/app/.gradle
70+
- backoffice_consumers_build:/app/build
71+
depends_on:
72+
- shared_mysql
73+
- shared_rabbitmq
74+
- backoffice_elasticsearch
75+
command: ["./gradlew", "bootRun", "--args", "backoffice_backend domain-events:rabbitmq:consume"]
76+
6077
backoffice_frontend_server_java:
6178
container_name: codely-java_ddd_example-backoffice_frontend_server
6279
build:
@@ -68,6 +85,7 @@ services:
6885
volumes:
6986
- .:/app:delegated
7087
- backoffice_frontend_gradle_cache:/app/.gradle
88+
- backoffice_frontend_build:/app/build
7189
depends_on:
7290
- shared_mysql
7391
- shared_rabbitmq
@@ -85,13 +103,37 @@ services:
85103
volumes:
86104
- .:/app:delegated
87105
- mooc_backend_gradle_cache:/app/.gradle
106+
- mooc_backend_build:/app/build
88107
depends_on:
89108
- shared_mysql
90109
- shared_rabbitmq
91110
- backoffice_elasticsearch
92111
command: ["./gradlew", "bootRun", "--args", "mooc_backend server"]
93112

113+
mooc_backend_consumers_java:
114+
container_name: codely-java_ddd_example-mooc_backend_consumers
115+
build:
116+
context: .
117+
dockerfile: Dockerfile
118+
restart: unless-stopped
119+
volumes:
120+
- .:/app:delegated
121+
- mooc_consumers_gradle_cache:/app/.gradle
122+
- mooc_consumers_build:/app/build
123+
depends_on:
124+
- shared_mysql
125+
- shared_rabbitmq
126+
- backoffice_elasticsearch
127+
command: ["./gradlew", "bootRun", "--args", "mooc_backend domain-events:rabbitmq:consume"]
128+
94129
volumes:
95130
backoffice_backend_gradle_cache:
131+
backoffice_backend_build:
132+
backoffice_consumers_gradle_cache:
133+
backoffice_consumers_build:
96134
backoffice_frontend_gradle_cache:
135+
backoffice_frontend_build:
97136
mooc_backend_gradle_cache:
137+
mooc_backend_build:
138+
mooc_consumers_gradle_cache:
139+
mooc_consumers_build:

0 commit comments

Comments
 (0)