Skip to content
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

Upgraded to Spring Boot 3 and EventStoreDB #38

Merged
merged 6 commits into from
Jan 4, 2023
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
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ services:
# EventStoreDB - Event Store
#######################################################
eventstore.db:
image: eventstore/eventstore:21.10.5-buster-slim
image: eventstore/eventstore:22.10.0-buster-slim
# use this image if you're running ARM-based proc like Apple M1
# image: ghcr.io/eventstore/eventstore:21.10.0-alpha-arm64v8
# image: eventstore/eventstore:22.10.0-alpha-arm64v8
environment:
- EVENTSTORE_CLUSTER_SIZE=1
- EVENTSTORE_RUN_PROJECTIONS=All
Expand Down
20 changes: 10 additions & 10 deletions samples/distributed-processes/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ repositories {

dependencies {
// Serialisation
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.4'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.4'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.14.0'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.14.0'

// EventStoreDB client
implementation 'com.eventstore:db-client-java:3.0.1'
implementation 'com.eventstore:db-client-java:4.0.0'

// Logging
implementation 'org.apache.logging.log4j:log4j-api:2.19.0'
implementation 'org.apache.logging.log4j:log4j-core:2.19.0'
implementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.19.0'

// Postgres and JPA for read models
implementation 'org.springframework.boot:spring-boot-starter-data-jpa:2.7.3'
implementation 'org.postgresql:postgresql:42.5.0'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa:3.0.1'
implementation 'org.postgresql:postgresql:42.5.1'

// Test frameworks
implementation 'junit:junit:4.13.2'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.0'
testImplementation 'org.junit.platform:junit-platform-launcher:1.9.0'
testImplementation 'com.fasterxml.jackson.core:jackson-databind:2.13.4'
testImplementation 'org.springframework.boot:spring-boot-starter-test:2.7.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.1'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.1'
testImplementation 'org.junit.platform:junit-platform-launcher:1.9.1'
testImplementation 'com.fasterxml.jackson.core:jackson-databind:2.14.0'
testImplementation 'org.springframework.boot:spring-boot-starter-test:3.0.1'
}

configurations {
Expand Down
4 changes: 2 additions & 2 deletions samples/distributed-processes/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ services:
# EventStoreDB - Event Store
#######################################################
eventstore.db:
image: eventstore/eventstore:21.10.5-buster-slim
image: eventstore/eventstore:22.10.0-buster-slim
# use this image if you're running ARM-based proc like Apple M1
# image: ghcr.io/eventstore/eventstore:21.10.0-alpha-arm64v8
# image: eventstore/eventstore:22.10.0-alpha-arm64v8
environment:
- EVENTSTORE_CLUSTER_SIZE=1
- EVENTSTORE_RUN_PROJECTIONS=All
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.eventstore.dbclient.*;
import io.eventdriven.distributedprocesses.core.http.ETag;
import io.eventdriven.distributedprocesses.core.serialization.EventSerializer;
import jakarta.persistence.EntityNotFoundException;

import javax.persistence.EntityNotFoundException;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -48,7 +48,7 @@ public Optional<Entity> get(Id id) {
public ETag add(Entity entity) {
return appendEvents(
entity,
AppendToStreamOptions.get().expectedRevision(ExpectedRevision.NO_STREAM)
AppendToStreamOptions.get().expectedRevision(ExpectedRevision.noStream())
);
}

Expand Down Expand Up @@ -86,7 +86,7 @@ public ETag getAndUpdate(
private Optional<List<Event>> getEvents(String streamId) {
ReadResult result;
try {
result = eventStore.readStream(streamId).get();
result = eventStore.readStream(streamId, ReadStreamOptions.get()).get();
} catch (Throwable e) {
Throwable innerException = e.getCause();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class EventStore {
public ReadResult read(String streamId) {
try {
var result = eventStore.readStream(streamId).get();
var result = eventStore.readStream(streamId, ReadStreamOptions.get()).get();

return new ReadResult.Success(result.getEvents().toArray(new ResolvedEvent[0]));
} catch (InterruptedException | ExecutionException e) {
Expand All @@ -29,7 +29,7 @@ public AppendResult append(String streamId, Object... events) {
try {
var result = eventStore.appendToStream(
streamId,
AppendToStreamOptions.get().expectedRevision(ExpectedRevision.NO_STREAM),
AppendToStreamOptions.get().expectedRevision(ExpectedRevision.noStream()),
eventsToAppend.iterator()
).get();

Expand All @@ -43,7 +43,7 @@ public AppendResult append(String streamId, Object... events) {
}
}

public AppendResult append(String streamId, StreamRevision expectedRevision, Object... events) {
public AppendResult append(String streamId, ExpectedRevision expectedRevision, Object... events) {
try {
var eventsToAppend = Arrays.stream(events)
.map(EventSerializer::serialize)
Expand All @@ -68,7 +68,7 @@ public DeleteResult deleteStream(String streamId) {
try {
eventStore.deleteStream(
streamId,
DeleteStreamOptions.get().expectedRevision(ExpectedRevision.STREAM_EXISTS)
DeleteStreamOptions.get().expectedRevision(ExpectedRevision.streamExists())
).get();

return new DeleteResult.Success();
Expand All @@ -80,7 +80,7 @@ public DeleteResult deleteStream(String streamId) {
}
}

public DeleteResult deleteStream(String streamId, StreamRevision expectedRevision) {
public DeleteResult deleteStream(String streamId, ExpectedRevision expectedRevision) {
try {
eventStore.deleteStream(
streamId,
Expand All @@ -105,7 +105,7 @@ public AppendResult setStreamMaxAge(String streamId, Duration duration) {

var result = eventStore.setStreamMetadata(
streamId,
AppendToStreamOptions.get().expectedRevision(ExpectedRevision.NO_STREAM),
AppendToStreamOptions.get().expectedRevision(ExpectedRevision.noStream()),
metadata
).get();

Expand Down Expand Up @@ -147,14 +147,14 @@ default Boolean succeeded() {

sealed public interface AppendResult {
record Success(
StreamRevision nextExpectedRevision, Position logPosition) implements AppendResult {
ExpectedRevision nextExpectedRevision, Position logPosition) implements AppendResult {
}

record StreamAlreadyExists(StreamRevision actual) implements AppendResult {
record StreamAlreadyExists(ExpectedRevision actual) implements AppendResult {
}

record Conflict(StreamRevision expected,
StreamRevision actual) implements AppendResult {
record Conflict(ExpectedRevision expected,
ExpectedRevision actual) implements AppendResult {
}

record UnexpectedFailure(Throwable t) implements AppendResult {
Expand All @@ -172,8 +172,8 @@ record Success() implements DeleteResult {
record StreamDoesNotExist() implements DeleteResult {
}

record Conflict(StreamRevision expected,
StreamRevision actual) implements DeleteResult {
record Conflict(ExpectedRevision expected,
ExpectedRevision actual) implements DeleteResult {
}

record UnexpectedFailure(Throwable t) implements DeleteResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
public final class SubscribeToAllOptionsFactory {
public static <EventType> SubscribeToAllOptions filterByType(Class<EventType> eventType) {
return SubscribeToAllOptions.get()
.filter(SubscriptionFilter.newBuilder().withEventTypePrefix(EventTypeMapper.toName(eventType)).build());
.filter(SubscriptionFilter.newBuilder().addStreamNamePrefix(EventTypeMapper.toName(eventType)).build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,12 @@ public static EventData serialize(Object event) {

public static <Command> EventData serialize(CommandEnvelope<Command> commandEnvelope) {
try {
return new EventData(
UUID.randomUUID(),
EventTypeMapper.toName(commandEnvelope.getClass()),
"application/json",
mapper.writeValueAsBytes(commandEnvelope.data()),
mapper.writeValueAsBytes(commandEnvelope.metadata())
);
return EventDataBuilder.json(
EventTypeMapper.toName(commandEnvelope.getClass()),
mapper.writeValueAsBytes(commandEnvelope.data())
)
.metadataAsBytes(mapper.writeValueAsBytes(commandEnvelope.metadata()))
.build();
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -93,7 +92,7 @@ public static <Event> Optional<EventEnvelope<Event>> deserializeEvent(Class<Even
var metadata = mapper.readValue(resolvedEvent.getEvent().getUserMetadata(), EventMetadata.class);


if(event == null)
if (event == null)
return Optional.empty();

return Optional.of(new EventEnvelope<>(event, metadata));
Expand All @@ -118,7 +117,7 @@ public static <Command> Optional<CommandEnvelope<Command>> deserializeCommand(Cl
var metadata = mapper.readValue(resolvedEvent.getEvent().getUserMetadata(), CommandMetadata.class);


if(event == null)
if (event == null)
return Optional.empty();

return Optional.of(new CommandEnvelope<>(event, metadata));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ public void enforcesUniqueness_WithStreamId() throws ExecutionException, Interru
// This one should succeed as we don't have such stream yet
eventStore.appendToStream(
shoppingCartStreamId,
AppendToStreamOptions.get().expectedRevision(ExpectedRevision.NO_STREAM),
AppendToStreamOptions.get().expectedRevision(ExpectedRevision.noStream()),
EventSerializer.serialize(shoppingCartOpened)
).get();

// This one will fail, as we're expecting that stream doesn't exist
try {
eventStore.appendToStream(
shoppingCartStreamId,
AppendToStreamOptions.get().expectedRevision(ExpectedRevision.NO_STREAM),
AppendToStreamOptions.get().expectedRevision(ExpectedRevision.noStream()),
EventSerializer.serialize(shoppingCartOpened)
).get();
} catch (ExecutionException exception) {
Expand All @@ -43,7 +43,7 @@ public void enforcesUniqueness_WithStreamId() throws ExecutionException, Interru
private EventStoreDBClient eventStore;

@BeforeEach
void beforeEach() throws ParseError {
void beforeEach() throws ConnectionStringParsingException {
EventStoreDBClientSettings settings = EventStoreDBConnectionString.parse("esdb://localhost:2113?tls=false");
this.eventStore = EventStoreDBClient.create(settings);
}
Expand Down
32 changes: 16 additions & 16 deletions samples/event-sourcing-esdb-aggregates/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'org.springframework.boot' version '2.7.0'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'org.springframework.boot' version '3.0.1'
id 'io.spring.dependency-management' version '1.1.0'
id 'java'
}

Expand All @@ -13,35 +13,35 @@ repositories {

dependencies {
// Spring Boot Web
implementation 'org.springframework.boot:spring-boot-starter-web:2.7.3'
implementation 'org.springframework.boot:spring-boot-starter-web:3.0.1'
// Validation
implementation 'org.springframework.boot:spring-boot-starter-validation:2.7.3'
implementation 'org.springframework.boot:spring-boot-starter-validation:3.0.1'
// Retry policy
implementation 'org.springframework.retry:spring-retry:1.3.3'
implementation 'org.springframework.retry:spring-retry:2.0.0'
// Swagger
implementation "org.springdoc:springdoc-openapi-ui:1.6.11"
implementation "org.springdoc:springdoc-openapi-ui:1.6.14"
// Serialisation
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.4'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.14.0'

// Log4J logging
implementation 'org.springframework.boot:spring-boot-starter-log4j2:2.7.3'
implementation 'org.springframework.boot:spring-boot-starter-log4j2:3.0.1'

// EventStoreDB client
implementation 'com.eventstore:db-client-java:3.0.1'
implementation 'com.eventstore:db-client-java:4.0.0'


// Postgres and JPA for read models
implementation 'org.springframework.boot:spring-boot-starter-data-jpa:2.7.3'
implementation 'org.postgresql:postgresql:42.5.0'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa:3.0.1'
implementation 'org.postgresql:postgresql:42.5.1'
implementation 'junit:junit:4.13.2'

// Test frameworks
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.boot:spring-boot-starter-test:3.0.1'

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.0'
testImplementation 'org.junit.platform:junit-platform-launcher:1.9.0'
testImplementation 'com.fasterxml.jackson.core:jackson-databind:2.13.4'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.1'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.1'
testImplementation 'org.junit.platform:junit-platform-launcher:1.9.1'
testImplementation 'com.fasterxml.jackson.core:jackson-databind:2.14.0'
}

configurations {
Expand Down
8 changes: 4 additions & 4 deletions samples/event-sourcing-esdb-aggregates/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ services:
# EventStoreDB - Event Store
#######################################################
eventstore.db:
image: eventstore/eventstore:21.10.1-buster-slim
image: eventstore/eventstore:22.10.0-buster-slim
# use this image if you're running ARM-based proc like Apple M1
# image: ghcr.io/eventstore/eventstore:21.10.0-alpha-arm64v8
# image: eventstore/eventstore:22.10.0-alpha-arm64v8
environment:
- EVENTSTORE_CLUSTER_SIZE=1
- EVENTSTORE_RUN_PROJECTIONS=All
Expand All @@ -29,7 +29,7 @@ services:
target: /var/log/eventstore
networks:
- eventstore.db

#######################################################
# Postgres
#######################################################
Expand Down Expand Up @@ -67,4 +67,4 @@ volumes:
eventstore-volume-data:
eventstore-volume-logs:
postgres:
pgadmin:
pgadmin:
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.springframework.validation.annotation.Validated;

import javax.validation.constraints.NotNull;
import jakarta.validation.constraints.NotNull;
import java.util.UUID;

public final class ShoppingCartsRequests {
Expand Down
Loading