Skip to content

Commit

Permalink
Cleaned up code
Browse files Browse the repository at this point in the history
  • Loading branch information
cer committed Mar 26, 2024
1 parent cdc34c9 commit 91624e7
Show file tree
Hide file tree
Showing 15 changed files with 100 additions and 80 deletions.
3 changes: 3 additions & 0 deletions eventuate-tram-examples-basic-event-common/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies {
implementation "org.springframework.boot:spring-boot-starter"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.eventuate.tram.examples.basic.events.common;

import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties(prefix = "event")
public class EventConfigurationProperties {

private String aggregateSuffix = "";

public String getAggregateSuffix() {
return aggregateSuffix;
}

public void setAggregateSuffix(String aggregateSuffix) {
this.aggregateSuffix = aggregateSuffix;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ apply plugin: 'org.springframework.boot'

dependencies {

implementation project(":eventuate-tram-examples-basic-event-common")

implementation "io.eventuate.tram.core:eventuate-tram-spring-events-subscriber-starter"

if (messageBroker == "kafka")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import io.eventuate.tram.events.subscriber.DomainEventEnvelope;
import io.eventuate.tram.events.subscriber.DomainEventHandlers;
import io.eventuate.tram.events.subscriber.DomainEventHandlersBuilder;
import io.eventuate.tram.examples.basic.events.common.EventConfigurationProperties;
import io.eventuate.tram.examples.basic.events.domain.AccountDebited;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;
Expand All @@ -18,9 +20,12 @@ public class AccountEventsConsumer {
public AccountEventsConsumer() {
}

@Autowired
private EventConfigurationProperties eventConfigurationProperties;

public DomainEventHandlers domainEventHandlers() {
return DomainEventHandlersBuilder
.forAggregateType("Account")
.forAggregateType("Account" + eventConfigurationProperties.getAggregateSuffix())
.onEvent(AccountDebited.class, this::handleAccountDebited)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import io.eventuate.tram.events.subscriber.DomainEventDispatcher;
import io.eventuate.tram.events.subscriber.DomainEventDispatcherFactory;
import io.eventuate.tram.examples.basic.events.common.EventConfigurationProperties;
import io.eventuate.tram.spring.consumer.common.TramNoopDuplicateMessageDetectorConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

@Configuration
@Import(TramNoopDuplicateMessageDetectorConfiguration.class)
@EnableConfigurationProperties(EventConfigurationProperties.class)
public class CqrsEventSubscriberConfiguration {

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

import static io.restassured.RestAssured.given;

@SpringBootTest(classes = CqrsEventSubscriberBrokerTest.Config.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@SpringBootTest(classes = CqrsEventSubscriberBrokerTest.Config.class,
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = {"event.aggregate.suffix=-${random.value}"})
public class CqrsEventSubscriberBrokerTest {

@Configuration
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
logging:
level:
io:
eventuate: DEBUG

server.port: 8081

spring:
datasource:
url: jdbc:mysql://${DOCKER_HOST_IP:localhost}/eventuate
username: mysqluser
password: mysqlpw
driver-class-name: com.mysql.cj.jdbc.Driver

eventuatelocal:
kafka:
bootstrap:
servers: ${DOCKER_HOST_IP:localhost}:9092
zookeeper:
connection:
string: ${DOCKER_HOST_IP:localhost}:2181

activemq:
url: tcp://${DOCKER_HOST_IP:localhost}:61616

rabbitmq:
broker:
addresses: ${DOCKER_HOST_IP:localhost}

---
spring:
profiles: postgres
datasource:
url: jdbc:postgresql://${DOCKER_HOST_IP:localhost}/eventuate
username: eventuate
password: eventuate
driver-class-name: org.postgresql.Driver

3 changes: 3 additions & 0 deletions eventuate-tram-examples-basic-event-publisher/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
apply plugin: 'org.springframework.boot'

dependencies {

implementation project(":eventuate-tram-examples-basic-event-common")

implementation "io.eventuate.tram.core:eventuate-tram-spring-events-publisher-starter"

runtimeOnly "io.eventuate.tram.core:eventuate-tram-spring-jdbc-$messageBroker"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package io.eventuate.tram.examples.basic.events.publisher;

import io.eventuate.tram.examples.basic.events.common.EventConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan
@EnableConfigurationProperties(EventConfigurationProperties.class)
public class EventPublisherConfiguration {


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.eventuate.tram.examples.basic.events.publisher;

import io.eventuate.tram.events.publisher.DomainEventPublisher;
import io.eventuate.tram.examples.basic.events.common.EventConfigurationProperties;
import io.eventuate.tram.examples.basic.events.domain.AccountDebited;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -14,20 +15,23 @@
@RestController
public class EventPublisherController {

private Logger logger = LoggerFactory.getLogger(getClass());
private final Logger logger = LoggerFactory.getLogger(getClass());

private DomainEventPublisher domainEventPublisher;
private final DomainEventPublisher domainEventPublisher;
private final EventConfigurationProperties eventConfigurationProperties;

@Autowired
public EventPublisherController(DomainEventPublisher domainEventPublisher) {
public EventPublisherController(DomainEventPublisher domainEventPublisher, EventConfigurationProperties eventConfigurationProperties) {
this.domainEventPublisher = domainEventPublisher;
this.eventConfigurationProperties = eventConfigurationProperties;
}

@PostMapping("/publish")
public void publish(@RequestBody PublishRequest publishRequest) {
logger.info("Publishing {}", publishRequest);
domainEventPublisher.publish("Account", publishRequest.accountId(), Collections.singletonList(new AccountDebited(publishRequest.amount())));
logger.info("Published {}", publishRequest);
String aggregateType = "Account" + eventConfigurationProperties.getAggregateSuffix();
logger.info("Publishing {} to {}", publishRequest, aggregateType);
domainEventPublisher.publish(aggregateType, publishRequest.accountId(), Collections.singletonList(new AccountDebited(publishRequest.amount())));
logger.info("Published {} to {}", publishRequest, aggregateType);
}

}
2 changes: 2 additions & 0 deletions eventuate-tram-examples-basic-event-subscriber/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ apply plugin: 'org.springframework.boot'

dependencies {

implementation project(":eventuate-tram-examples-basic-event-common")

implementation "io.eventuate.tram.core:eventuate-tram-spring-events-subscriber-starter"

runtimeOnly "io.eventuate.tram.core:eventuate-tram-spring-jdbc-$messageBroker"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import io.eventuate.tram.events.subscriber.DomainEventEnvelope;
import io.eventuate.tram.events.subscriber.DomainEventHandlers;
import io.eventuate.tram.events.subscriber.DomainEventHandlersBuilder;
import io.eventuate.tram.examples.basic.events.common.EventConfigurationProperties;
import io.eventuate.tram.examples.basic.events.domain.AccountDebited;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;
Expand All @@ -15,12 +17,15 @@ public class AccountEventsConsumer {
private final Logger logger = LoggerFactory.getLogger(getClass());
private final BlockingQueue<DomainEventEnvelope<AccountDebited>> queue = new LinkedBlockingDeque<>();

@Autowired
private EventConfigurationProperties eventConfigurationProperties;

public AccountEventsConsumer() {
}

public DomainEventHandlers domainEventHandlers() {
return DomainEventHandlersBuilder
.forAggregateType("Account")
.forAggregateType("Account" + eventConfigurationProperties.getAggregateSuffix())
.onEvent(AccountDebited.class, this::handleAccountDebited)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import io.eventuate.tram.events.subscriber.DomainEventDispatcher;
import io.eventuate.tram.events.subscriber.DomainEventDispatcherFactory;
import io.eventuate.tram.examples.basic.events.common.EventConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(EventConfigurationProperties.class)
public class EventSubscriberConfiguration {

@Bean
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include 'eventuate-tram-examples-basic-message-common'
include 'eventuate-tram-examples-basic-message-producer'
include 'eventuate-tram-examples-basic-message-consumer'
include 'eventuate-tram-examples-basic-event-common'
include 'eventuate-tram-examples-basic-event-publisher'
include 'eventuate-tram-examples-basic-event-subscriber'
include 'eventuate-tram-examples-basic-event-cqrs-subscriber'
Expand Down

0 comments on commit 91624e7

Please sign in to comment.