Skip to content

docs(scenarios): Add scenarios documentation #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion async/async-commons/async-commons.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies {
compileOnly 'io.projectreactor:reactor-core'
api 'com.fasterxml.jackson.core:jackson-databind'
api 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'
implementation 'commons-io:commons-io:2.17.0'
implementation 'commons-io:commons-io:2.18.0'
implementation 'io.cloudevents:cloudevents-json-jackson:4.0.1'

testImplementation 'io.projectreactor:reactor-test'
Expand Down
3 changes: 2 additions & 1 deletion async/async-kafka/async-kafka.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ dependencies {
api project(':domain-events-api')
api project(':async-commons')
api 'io.projectreactor.kafka:reactor-kafka:1.3.23'
api 'io.cloudevents:cloudevents-json-jackson:4.0.1'

implementation 'io.cloudevents:cloudevents-json-jackson:4.0.1'
}
4 changes: 3 additions & 1 deletion async/async-rabbit/async-rabbit.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ dependencies {
api 'io.projectreactor.rabbitmq:reactor-rabbitmq:1.5.6'
api 'com.rabbitmq:amqp-client'
api 'com.fasterxml.jackson.core:jackson-databind'
testImplementation 'io.projectreactor:reactor-test'

implementation 'io.cloudevents:cloudevents-json-jackson:4.0.1'

testImplementation 'io.projectreactor:reactor-test'
}
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ buildscript {

plugins {
id 'jacoco'
id 'org.sonarqube' version '5.1.0.4882'
id 'org.springframework.boot' version '3.3.4' apply false
id 'org.sonarqube' version '6.0.0.5145'
id 'org.springframework.boot' version '3.4.0' apply false
id 'io.github.gradle-nexus.publish-plugin' version '2.0.0'
id 'co.com.bancolombia.cleanArchitecture' version '3.17.26'
id 'co.com.bancolombia.cleanArchitecture' version '3.20.2'
}

repositories {
Expand Down
20 changes: 19 additions & 1 deletion docs/docs/reactive-commons/1-getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ dependencies {
}
```

Note: If you will use Cloud Events, you should include the Cloud Events dependency:

```groovy
dependencies {
implementation 'io.cloudevents:cloudevents-json-jackson:4.0.1'
}
```

```groovy

### Configuration properties

Also you need to include the name for your app in the `application.properties`, it is important because this value will
Expand Down Expand Up @@ -83,7 +93,7 @@ spring:

You can also set it in runtime for example from a secret, so you can create the `RabbitProperties` bean like:

```java title="org.reactivecommons.async.rabbit.standalone.config.RabbitProperties"
```java title="org.reactivecommons.async.rabbit.config.RabbitProperties"

@Configuration
public class MyRabbitMQConfig {
Expand Down Expand Up @@ -206,6 +216,14 @@ dependencies {
}
```

Note: If you will use Cloud Events, you should include the Cloud Events dependency:

```groovy
dependencies {
implementation 'io.cloudevents:cloudevents-json-jackson:4.0.1'
}
```

### Configuration properties

Also you need to include the name for your app in the `application.properties`, it is important because this value will
Expand Down
53 changes: 52 additions & 1 deletion docs/docs/reactive-commons/11-creating-a-cloud-event.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,19 @@ In order to instantiate a CloudEvent you may need to include the dependencies:

```groovy
implementation 'io.cloudevents:cloudevents-core:<version>'
// or
implementation 'io.cloudevents:cloudevents-json-jackson:<version>'
```

## Creating a CloudEvent instance with our Data wrapper

add this classes:

```java
import io.cloudevents.core.builder.CloudEventBuilder;
import io.cloudevents.CloudEvent;
import org.reactivecommons.async.commons.converters.json.CloudEventBuilderExt;
```
## Creating a CloudEvent instance

```java
CloudEvent commandCloudEvent = CloudEventBuilder.v1()
Expand All @@ -44,4 +55,44 @@ CloudEvent eventCloudEvent = CloudEventBuilder.v1()
.withTime(OffsetDateTime.now())
.withData("application/json", CloudEventBuilderExt.asCloudEventData(eventData)) // eventData is your own object
.build();
```

## Creating a CloudEvent instance with jackson wrapper Data wrapper

add this classes:

```java
import io.cloudevents.core.builder.CloudEventBuilder;
import io.cloudevents.CloudEvent;
import io.cloudevents.jackson.JsonCloudEventData;
import com.fasterxml.jackson.databind.ObjectMapper;
```

```java
ObjectMapper mapper = new ObjectMapper(); // You should convert your object to a JsonNode

CloudEvent commandCloudEvent = CloudEventBuilder.v1()
.withId(UUID.randomUUID().toString())
.withSource(URI.create("https://reactivecommons.org/foos"))
.withType("some.command.name")
.withTime(OffsetDateTime.now())
.withData("application/json", JsonCloudEventData.wrap(mapper.valueToTree(commandData))) // commandData is your own object
.build();

CloudEvent queryCloudEvent = CloudEventBuilder.v1()
.withId(UUID.randomUUID().toString())
.withSource(URI.create("https://reactivecommons.org/foos"))
.withType("some.query.name")
.withTime(OffsetDateTime.now())
.withData("application/json", JsonCloudEventData.wrap(mapper.valueToTree(queryData))) // queryData is your own object
.build();

CloudEvent eventCloudEvent = CloudEventBuilder.v1()
.withId(UUID.randomUUID().toString())
.withSource(URI.create("https://reactivecommons.org/foos"))
.withType("some.event.name")
.withDataContentType("application/json")
.withTime(OffsetDateTime.now())
.withData("application/json", JsonCloudEventData.wrap(mapper.valueToTree(eventData))) // eventData is your own object
.build();
```
5 changes: 4 additions & 1 deletion docs/docs/reactive-commons/3-sending-a-command.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public interface DirectAsyncGateway {
}
```

You can send a CloudEvent or a Command\<T> to a target application. You also can send a command to a specific domain
(remote broker out of you application context).

## Enabling autoconfiguration

To send Commands you should enable the respecting spring boot autoconfiguration using the `@EnableDomainEventBus` annotation
Expand All @@ -50,7 +53,7 @@ For example:
public class ReactiveDirectAsyncGateway {
public static final String TARGET_NAME = "other-app";// refers to remote spring.application.name property
public static final String SOME_COMMAND_NAME = "some.command.name";
private final DirectAsyncGateway gateway; // Auto injectec bean created by the @EnableDirectAsyncGateway annotation
private final DirectAsyncGateway gateway; // Auto injected bean created by the @EnableDirectAsyncGateway annotation

public Mono<Void> runRemoteJob(Object command/*change for proper model*/) {
return gateway.sendCommand(new Command<>(SOME_COMMAND_NAME, UUID.randomUUID().toString(), command), TARGET_NAME);
Expand Down
3 changes: 3 additions & 0 deletions docs/docs/reactive-commons/4-making-an-async-query.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public interface DirectAsyncGateway {

In this method the Class\<R> called type is the return type of the query, represented by a JSON Serializable object

You can send a CloudEvent or an AsyncQuery\<T> to a target application. You also can send a query to a specific domain
(remote broker out of you application context).

## Enabling autoconfiguration

To do an Async Query you should enable the respecting spring boot autoconfiguration using the `@EnableDirectAsyncGateway` annotation
Expand Down
28 changes: 20 additions & 8 deletions docs/docs/reactive-commons/5-handler-registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,24 @@ The next methods are the main methods that you can use to register a handler.

```java
public class HandlerRegistry {
public <T> HandlerRegistry listenEvent(String eventName, EventHandler<T> handler, Class<T> eventClass){...}
public <T> HandlerRegistry handleDynamicEvents(String eventNamePattern, EventHandler<T> handler, Class<T> eventClass){...}
public <T> HandlerRegistry listenNotificationEvent(String eventName, EventHandler<T> handler, Class<T> eventClass){...}
public <T> HandlerRegistry handleCommand(String commandName, CommandHandler<T> fn, Class<T> commandClass){...}
public <T, R> HandlerRegistry serveQuery(String resource, QueryHandler<T, R> handler, Class<R> queryClass){...}
public <R> HandlerRegistry serveQuery(String resource, QueryHandlerDelegate<Void, R> handler, Class<R> queryClass) {...}
// ... other methods for eda variant and overloads
public <T> HandlerRegistry listenDomainEvent(String domain, String eventName, DomainEventHandler<T> handler, Class<T> eventClass)
public HandlerRegistry listenDomainCloudEvent(String domain, String eventName, CloudEventHandler handler)
public <T> HandlerRegistry listenEvent(String eventName, DomainEventHandler<T> handler, Class<T> eventClass)
public HandlerRegistry listenCloudEvent(String eventName, CloudEventHandler handler)
public <T> HandlerRegistry listenNotificationEvent(String eventName, DomainEventHandler<T> handler, Class<T> eventClass)
public HandlerRegistry listenNotificationCloudEvent(String eventName, CloudEventHandler handler)
public <T> HandlerRegistry handleDynamicEvents(String eventNamePattern, DomainEventHandler<T> handler, Class<T> eventClass)
public HandlerRegistry handleDynamicCloudEvents(String eventNamePattern, CloudEventHandler handler)
public <T> HandlerRegistry handleCommand(String commandName, DomainCommandHandler<T> fn, Class<T> commandClass)
public HandlerRegistry handleCloudEventCommand(String commandName, CloudCommandHandler handler)
public <T, R> HandlerRegistry serveQuery(String resource, QueryHandler<T, R> handler, Class<R> queryClass)
public <R> HandlerRegistry serveQuery(String resource, QueryHandlerDelegate<Void, R> handler, Class<R> queryClass)
public <R> HandlerRegistry serveCloudEventQuery(String resource, QueryHandler<R, CloudEvent> handler)
public <R> HandlerRegistry serveCloudEventQuery(String resource, QueryHandlerDelegate<Void, CloudEvent> handler)
}
```
```

Methods that Has `CloudEvent` in the name are related to the CloudEvent specification.

Methods that has `domain` String argument are related to the multi-broker support, this support is limited to listen events
from different domains (brokers) independent of the technology.
2 changes: 1 addition & 1 deletion docs/docs/reactive-commons/9-configuration-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ You can override this settings programmatically through a `AsyncPropsDomainPrope
```java
package sample;

import org.reactivecommons.async.rabbit.standalone.config.RabbitProperties;
import org.reactivecommons.async.rabbit.config.RabbitProperties;
import org.reactivecommons.async.rabbit.config.props.AsyncProps;
import org.reactivecommons.async.rabbit.config.props.AsyncRabbitPropsDomainProperties;
import org.springframework.context.annotation.Bean;
Expand Down
Loading
Loading