Skip to content

Commit

Permalink
docs(bean): Add bean sample to generate configuration programatically
Browse files Browse the repository at this point in the history
  • Loading branch information
juancgalvis committed Apr 12, 2024
1 parent c5bf491 commit 453175a
Show file tree
Hide file tree
Showing 11 changed files with 240 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -644,4 +644,5 @@ MigrationBackup/
# End of https://www.toptal.com/developers/gitignore/api/macos,linux,windows,gradle,java,intellij,visualstudio,eclipse
contiperf-report

samples/async/local-example/
samples/async/local-example/
docs-src
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,21 @@ public AsyncPropsDomainProperties() {
public AsyncPropsDomainProperties(Map<? extends String, ? extends AsyncProps> m) {
super(m);
}

public static AsyncPropsDomainPropertiesBuilder builder() {
return new AsyncPropsDomainPropertiesBuilder();
}

public static class AsyncPropsDomainPropertiesBuilder {
private final HashMap<String, AsyncProps> domains = new HashMap<>();

public AsyncPropsDomainPropertiesBuilder withDomain(String domain, AsyncProps props) {
domains.put(domain, props);
return this;
}

public AsyncPropsDomainProperties build() {
return new AsyncPropsDomainProperties(domains);
}
}
}
2 changes: 1 addition & 1 deletion docs/asciidoc/getting-started.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Start RabbitMQ on your local machine with all the defaults (e.g. AMQP port is 56

==== Sample Spring Boot Application

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.
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.

To build your own application using the Reactive Commons API,
you need to include a dependency to Reactive Commons.
Expand Down
6 changes: 3 additions & 3 deletions docs/asciidoc/overview.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The purpose of reactive-commons is to provide a set of abstractions and implemen

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.

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.
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.

=== Project Reactor

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

=== Reactive API for Event Mechanism

Reactive Commons is a reactive API for asyncronous message driven communication based on Reactor.
Reactive Commons is a reactive API for asynchronous message driven communication based on Reactor.
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.
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.

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.
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.

==== Events - Pub/Sub
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ public interface DomainEventBus {
<T> Publisher<Void> emit(DomainEvent<T> event);

Publisher<Void> emit(CloudEvent event);

}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=2.1.0
version=2.1.1
springBootVersion=3.2.4
reactorRabbitVersion=1.5.5
cloudEventsVersion=3.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ public class HandlersConfig {
@Primary
public HandlerRegistry handlerRegistrySubs(UseCase useCase) {
return HandlerRegistry.register()
.listenEvent(Constants.MEMBER_REMOVED, useCase::removeMember, RemovedMemberEvent.class)
.serveQuery(Constants.GET_TEAMS, useCase::getTeams, String.class)
.serveQuery(Constants.GET_TEAM_MEMBERS, useCase::getTeam, String.class)
.handleCommand(Constants.ADD_MEMBER, useCase::addMember, AddMemberCommand.class)
.listenEvent(Constants.MEMBER_REMOVED, useCase::removeMember, RemovedMemberEvent.class)
.handleDynamicEvents("purchase.*", useCase::removeMember, RemovedMemberEvent.class)
.listenNotificationEvent(Constants.DATA_RESET, useCase::reset, String.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package sample;

import org.reactivecommons.async.rabbit.config.RabbitProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

@Configuration
public class MyRabbitMQConfig {

@Bean
@Primary
public RabbitProperties customRabbitProperties(){
RabbitProperties properties = new RabbitProperties();
properties.setHost("localhost");
properties.setPort(5672);
properties.setVirtualHost("/");
properties.setUsername("guest");
properties.setPassword("guest");
return properties;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package sample;

import org.reactivecommons.async.rabbit.config.RabbitProperties;
import org.reactivecommons.async.rabbit.config.props.AsyncProps;
import org.reactivecommons.async.rabbit.config.props.AsyncPropsDomainProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;

//@Configuration
public class MyDomainConfig {

@Bean
@Primary
public AsyncPropsDomainProperties customDomainProperties() {
RabbitProperties propertiesApp = new RabbitProperties();
propertiesApp.setHost("localhost");
propertiesApp.setPort(5672);
propertiesApp.setVirtualHost("/");
propertiesApp.setUsername("guest");
propertiesApp.setPassword("guest");

RabbitProperties propertiesAccounts = new RabbitProperties();
propertiesAccounts.setHost("localhost");
propertiesAccounts.setPort(5672);
propertiesAccounts.setVirtualHost("/accounts");
propertiesAccounts.setUsername("guest");
propertiesAccounts.setPassword("guest");

return AsyncPropsDomainProperties.builder()
.withDomain("app", AsyncProps.builder()
.connectionProperties(propertiesApp)
.build())
.withDomain("accounts", AsyncProps.builder()
.connectionProperties(propertiesAccounts)
.build())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"client": "Thunder Client",
"collectionName": "reactive-commons-eda-domain-a",
"dateExported": "2024-04-03T13:34:13.855Z",
"version": "1.1",
"folders": [],
"requests": [
{
"_id": "854a1a8b-792f-4e93-81c0-7303cac31c3b",
"colId": "4a3f48fc-b39b-4ae2-b90f-4b8dad86096a",
"containerId": "",
"name": "AddMember",
"url": "http://localhost:4002/api/teams/ingsw/members",
"method": "POST",
"sortNum": 20000,
"created": "2024-04-03T12:55:28.297Z",
"modified": "2024-04-03T13:29:04.872Z",
"headers": [],
"params": [],
"body": {
"type": "json",
"raw": "{\n \"name\": \"Juan\",\n \"username\": \"juancgalvis2\"\n}",
"form": []
},
"tests": []
},
{
"_id": "8790f03f-9047-409e-8c6a-0435d71eacd4",
"colId": "4a3f48fc-b39b-4ae2-b90f-4b8dad86096a",
"containerId": "",
"name": "GetTeams",
"url": "http://localhost:4002/api/teams",
"method": "GET",
"sortNum": 40000,
"created": "2024-04-03T12:55:28.300Z",
"modified": "2024-04-03T12:57:16.723Z",
"headers": [],
"params": [],
"tests": []
},
{
"_id": "3aeaf5d0-5f30-4e2c-a1da-d8ae26424d68",
"colId": "4a3f48fc-b39b-4ae2-b90f-4b8dad86096a",
"containerId": "",
"name": "GetTeamMembers",
"url": "http://localhost:4002/api/teams/ingsw",
"method": "GET",
"sortNum": 50000,
"created": "2024-04-03T12:55:28.301Z",
"modified": "2024-04-03T13:18:25.708Z",
"headers": [],
"params": [],
"tests": []
},
{
"_id": "535f2605-b22c-45c2-b188-24ad850d9c8b",
"colId": "4a3f48fc-b39b-4ae2-b90f-4b8dad86096a",
"containerId": "",
"name": "RemoveTeamMember",
"url": "http://localhost:4002/api/teams/ingsw/members/juancgalvis2",
"method": "DELETE",
"sortNum": 60000,
"created": "2024-04-03T12:55:28.302Z",
"modified": "2024-04-03T13:29:48.474Z",
"headers": [],
"params": [],
"tests": []
}
]
}
84 changes: 84 additions & 0 deletions samples/async/thunder-collection_reactive-commons.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"client": "Thunder Client",
"collectionName": "reactive-commons",
"dateExported": "2024-04-03T13:33:34.743Z",
"version": "1.1",
"folders": [],
"requests": [
{
"_id": "067ac0d0-1a9f-4327-a502-62c8e7bb5ffd",
"colId": "551afab7-c4ab-4191-bc26-2443aab6bc23",
"containerId": "",
"name": "AddMember",
"url": "http://localhost:4001/api/teams/ingsw/members",
"method": "POST",
"sortNum": 20000,
"created": "2024-04-02T20:49:04.005Z",
"modified": "2024-04-02T20:54:44.056Z",
"headers": [],
"params": [],
"body": {
"type": "json",
"raw": "{\n \"name\": \"Juan\",\n \"username\": \"juancgalvis\"\n}",
"form": []
},
"tests": []
},
{
"_id": "9f5f058d-4758-4ec2-85a1-7b6a118e0c5f",
"colId": "551afab7-c4ab-4191-bc26-2443aab6bc23",
"containerId": "",
"name": "GetTeams",
"url": "http://localhost:4001/api/teams",
"method": "GET",
"sortNum": 40000,
"created": "2024-04-02T20:56:13.923Z",
"modified": "2024-04-02T20:56:26.311Z",
"headers": [],
"params": [],
"tests": []
},
{
"_id": "4c972d14-2c3c-4f55-bf36-f652b4ea877f",
"colId": "551afab7-c4ab-4191-bc26-2443aab6bc23",
"containerId": "",
"name": "GetTeamMembers",
"url": "http://localhost:4001/api/teams/ingsw",
"method": "GET",
"sortNum": 50000,
"created": "2024-04-02T20:56:54.150Z",
"modified": "2024-04-02T20:58:17.562Z",
"headers": [],
"params": [],
"tests": []
},
{
"_id": "476ad00a-fc04-4911-9731-16532e54a385",
"colId": "551afab7-c4ab-4191-bc26-2443aab6bc23",
"containerId": "",
"name": "RemoveTeamMember",
"url": "http://localhost:4001/api/teams/ingsw/members/juancgalvis",
"method": "DELETE",
"sortNum": 60000,
"created": "2024-04-02T20:57:35.952Z",
"modified": "2024-04-02T20:57:48.657Z",
"headers": [],
"params": [],
"tests": []
},
{
"_id": "abb1d0a5-ba07-4be3-a5a6-ab260e5f1ab7",
"colId": "551afab7-c4ab-4191-bc26-2443aab6bc23",
"containerId": "",
"name": "RemoveTeams",
"url": "http://localhost:4001/api/teams",
"method": "DELETE",
"sortNum": 70000,
"created": "2024-04-02T20:58:32.517Z",
"modified": "2024-04-02T20:58:53.275Z",
"headers": [],
"params": [],
"tests": []
}
]
}

0 comments on commit 453175a

Please sign in to comment.