Skip to content

Commit 453175a

Browse files
committed
docs(bean): Add bean sample to generate configuration programatically
1 parent c5bf491 commit 453175a

File tree

11 files changed

+240
-7
lines changed

11 files changed

+240
-7
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,4 +644,5 @@ MigrationBackup/
644644
# End of https://www.toptal.com/developers/gitignore/api/macos,linux,windows,gradle,java,intellij,visualstudio,eclipse
645645
contiperf-report
646646

647-
samples/async/local-example/
647+
samples/async/local-example/
648+
docs-src

async/async-rabbit-starter-eda/src/main/java/org/reactivecommons/async/rabbit/config/props/AsyncPropsDomainProperties.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,21 @@ public AsyncPropsDomainProperties() {
1818
public AsyncPropsDomainProperties(Map<? extends String, ? extends AsyncProps> m) {
1919
super(m);
2020
}
21+
22+
public static AsyncPropsDomainPropertiesBuilder builder() {
23+
return new AsyncPropsDomainPropertiesBuilder();
24+
}
25+
26+
public static class AsyncPropsDomainPropertiesBuilder {
27+
private final HashMap<String, AsyncProps> domains = new HashMap<>();
28+
29+
public AsyncPropsDomainPropertiesBuilder withDomain(String domain, AsyncProps props) {
30+
domains.put(domain, props);
31+
return this;
32+
}
33+
34+
public AsyncPropsDomainProperties build() {
35+
return new AsyncPropsDomainProperties(domains);
36+
}
37+
}
2138
}

docs/asciidoc/getting-started.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Start RabbitMQ on your local machine with all the defaults (e.g. AMQP port is 56
1818

1919
==== Sample Spring Boot Application
2020

21-
The Spring Boot sample publishes and cosumes messages with the `DomainEventBus`. This application illustrates how to configure Reactive Commons using RabbitMQ in a Spring Boot environment.
21+
The Spring Boot sample publishes and consumes messages with the `DomainEventBus`. This application illustrates how to configure Reactive Commons using RabbitMQ in a Spring Boot environment.
2222

2323
To build your own application using the Reactive Commons API,
2424
you need to include a dependency to Reactive Commons.

docs/asciidoc/overview.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The purpose of reactive-commons is to provide a set of abstractions and implemen
66

77
Even though the main purpose is to provide such abstractions in a mostly generic way such abstractions would be of little use without a concrete implementation so we provide some implementations in a best effors maner that aim to be easy to change, personalize and extend.
88

9-
The first approach to this work was to release a very simple abstractions and a corresponding implementation over asyncronous message driven communication between microservices build on top of project-reactor and spring boot.
9+
The first approach to this work was to release a very simple abstractions and a corresponding implementation over asynchronous message driven communication between microservices build on top of project-reactor and spring boot.
1010

1111
=== Project Reactor
1212

@@ -27,11 +27,11 @@ avoiding unnecessary intermediate buffering or blocking.
2727

2828
=== Reactive API for Event Mechanism
2929

30-
Reactive Commons is a reactive API for asyncronous message driven communication based on Reactor.
30+
Reactive Commons is a reactive API for asynchronous message driven communication based on Reactor.
3131
Reactive Commons API enables messages to be published over a event bus like RabbitMQ or SNS/SQS and consumed using functional APIs with non-blocking back-pressure and low overheads.
3232
It enables applications using Reactor to use RabbitMQ or SNS/SQS as a message bus, integrating it with other systems to provide an end-to-end reactive system.
3333

34-
When we talk about asyncronous message driven communication, we can use several sematic ways to use the term "message". So, we can talk about Events, Commands and Queries.
34+
When we talk about asynchronous message driven communication, we can use several sematic ways to use the term "message". So, we can talk about Events, Commands and Queries.
3535

3636
==== Events - Pub/Sub
3737
Events represent a fact inside the domain, it is the representation of a decision or a state change that a system want to notify to its subscribers. Events represents facts that nobody can change, so events are not intentions or requests of anything, An example may be and UserRegistered or a NotificationSent.

domain/domain-events/src/main/java/org/reactivecommons/api/domain/DomainEventBus.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@ public interface DomainEventBus {
77
<T> Publisher<Void> emit(DomainEvent<T> event);
88

99
Publisher<Void> emit(CloudEvent event);
10-
1110
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version=2.1.0
1+
version=2.1.1
22
springBootVersion=3.2.4
33
reactorRabbitVersion=1.5.5
44
cloudEventsVersion=3.0.0

samples/async/async-receiver-responder/src/main/java/sample/HandlersConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ public class HandlersConfig {
1414
@Primary
1515
public HandlerRegistry handlerRegistrySubs(UseCase useCase) {
1616
return HandlerRegistry.register()
17+
.listenEvent(Constants.MEMBER_REMOVED, useCase::removeMember, RemovedMemberEvent.class)
1718
.serveQuery(Constants.GET_TEAMS, useCase::getTeams, String.class)
1819
.serveQuery(Constants.GET_TEAM_MEMBERS, useCase::getTeam, String.class)
1920
.handleCommand(Constants.ADD_MEMBER, useCase::addMember, AddMemberCommand.class)
2021
.listenEvent(Constants.MEMBER_REMOVED, useCase::removeMember, RemovedMemberEvent.class)
22+
.handleDynamicEvents("purchase.*", useCase::removeMember, RemovedMemberEvent.class)
2123
.listenNotificationEvent(Constants.DATA_RESET, useCase::reset, String.class);
2224
}
2325
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package sample;
2+
3+
import org.reactivecommons.async.rabbit.config.RabbitProperties;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.context.annotation.Primary;
7+
8+
@Configuration
9+
public class MyRabbitMQConfig {
10+
11+
@Bean
12+
@Primary
13+
public RabbitProperties customRabbitProperties(){
14+
RabbitProperties properties = new RabbitProperties();
15+
properties.setHost("localhost");
16+
properties.setPort(5672);
17+
properties.setVirtualHost("/");
18+
properties.setUsername("guest");
19+
properties.setPassword("guest");
20+
return properties;
21+
}
22+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package sample;
2+
3+
import org.reactivecommons.async.rabbit.config.RabbitProperties;
4+
import org.reactivecommons.async.rabbit.config.props.AsyncProps;
5+
import org.reactivecommons.async.rabbit.config.props.AsyncPropsDomainProperties;
6+
import org.springframework.context.annotation.Bean;
7+
import org.springframework.context.annotation.Primary;
8+
9+
//@Configuration
10+
public class MyDomainConfig {
11+
12+
@Bean
13+
@Primary
14+
public AsyncPropsDomainProperties customDomainProperties() {
15+
RabbitProperties propertiesApp = new RabbitProperties();
16+
propertiesApp.setHost("localhost");
17+
propertiesApp.setPort(5672);
18+
propertiesApp.setVirtualHost("/");
19+
propertiesApp.setUsername("guest");
20+
propertiesApp.setPassword("guest");
21+
22+
RabbitProperties propertiesAccounts = new RabbitProperties();
23+
propertiesAccounts.setHost("localhost");
24+
propertiesAccounts.setPort(5672);
25+
propertiesAccounts.setVirtualHost("/accounts");
26+
propertiesAccounts.setUsername("guest");
27+
propertiesAccounts.setPassword("guest");
28+
29+
return AsyncPropsDomainProperties.builder()
30+
.withDomain("app", AsyncProps.builder()
31+
.connectionProperties(propertiesApp)
32+
.build())
33+
.withDomain("accounts", AsyncProps.builder()
34+
.connectionProperties(propertiesAccounts)
35+
.build())
36+
.build();
37+
}
38+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"client": "Thunder Client",
3+
"collectionName": "reactive-commons-eda-domain-a",
4+
"dateExported": "2024-04-03T13:34:13.855Z",
5+
"version": "1.1",
6+
"folders": [],
7+
"requests": [
8+
{
9+
"_id": "854a1a8b-792f-4e93-81c0-7303cac31c3b",
10+
"colId": "4a3f48fc-b39b-4ae2-b90f-4b8dad86096a",
11+
"containerId": "",
12+
"name": "AddMember",
13+
"url": "http://localhost:4002/api/teams/ingsw/members",
14+
"method": "POST",
15+
"sortNum": 20000,
16+
"created": "2024-04-03T12:55:28.297Z",
17+
"modified": "2024-04-03T13:29:04.872Z",
18+
"headers": [],
19+
"params": [],
20+
"body": {
21+
"type": "json",
22+
"raw": "{\n \"name\": \"Juan\",\n \"username\": \"juancgalvis2\"\n}",
23+
"form": []
24+
},
25+
"tests": []
26+
},
27+
{
28+
"_id": "8790f03f-9047-409e-8c6a-0435d71eacd4",
29+
"colId": "4a3f48fc-b39b-4ae2-b90f-4b8dad86096a",
30+
"containerId": "",
31+
"name": "GetTeams",
32+
"url": "http://localhost:4002/api/teams",
33+
"method": "GET",
34+
"sortNum": 40000,
35+
"created": "2024-04-03T12:55:28.300Z",
36+
"modified": "2024-04-03T12:57:16.723Z",
37+
"headers": [],
38+
"params": [],
39+
"tests": []
40+
},
41+
{
42+
"_id": "3aeaf5d0-5f30-4e2c-a1da-d8ae26424d68",
43+
"colId": "4a3f48fc-b39b-4ae2-b90f-4b8dad86096a",
44+
"containerId": "",
45+
"name": "GetTeamMembers",
46+
"url": "http://localhost:4002/api/teams/ingsw",
47+
"method": "GET",
48+
"sortNum": 50000,
49+
"created": "2024-04-03T12:55:28.301Z",
50+
"modified": "2024-04-03T13:18:25.708Z",
51+
"headers": [],
52+
"params": [],
53+
"tests": []
54+
},
55+
{
56+
"_id": "535f2605-b22c-45c2-b188-24ad850d9c8b",
57+
"colId": "4a3f48fc-b39b-4ae2-b90f-4b8dad86096a",
58+
"containerId": "",
59+
"name": "RemoveTeamMember",
60+
"url": "http://localhost:4002/api/teams/ingsw/members/juancgalvis2",
61+
"method": "DELETE",
62+
"sortNum": 60000,
63+
"created": "2024-04-03T12:55:28.302Z",
64+
"modified": "2024-04-03T13:29:48.474Z",
65+
"headers": [],
66+
"params": [],
67+
"tests": []
68+
}
69+
]
70+
}

0 commit comments

Comments
 (0)