Skip to content
Open
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
10 changes: 10 additions & 0 deletions spring-modulith-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
<artifactId>spring-modulith-events-core</artifactId>
<version>2.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.modulith</groupId>
<artifactId>spring-modulith-events-couchbase</artifactId>
<version>2.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.modulith</groupId>
<artifactId>spring-modulith-events-jackson</artifactId>
Expand Down Expand Up @@ -144,6 +149,11 @@
<artifactId>spring-modulith-starter-core</artifactId>
<version>2.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.modulith</groupId>
<artifactId>spring-modulith-starter-couchbase</artifactId>
<version>2.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.modulith</groupId>
<artifactId>spring-modulith-starter-insight</artifactId>
Expand Down
1 change: 1 addition & 0 deletions spring-modulith-events/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<module>spring-modulith-events-amqp</module>
<module>spring-modulith-events-api</module>
<module>spring-modulith-events-core</module>
<module>spring-modulith-events-couchbase</module>
<module>spring-modulith-events-jackson</module>
<module>spring-modulith-events-jdbc</module>
<module>spring-modulith-events-jms</module>
Expand Down
93 changes: 93 additions & 0 deletions spring-modulith-events/spring-modulith-events-couchbase/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.modulith</groupId>
<artifactId>spring-modulith-events</artifactId>
<version>2.2.0-SNAPSHOT</version>
</parent>

<name>Spring Modulith - Events - CouchBase-based repository</name>
<artifactId>spring-modulith-events-couchbase</artifactId>

<properties>
<module.name>spring.modulith.events.couchbase</module.name>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-bom</artifactId>
<version>${testcontainers.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>

<dependency>
<groupId>org.jspecify</groupId>
<artifactId>jspecify</artifactId>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>spring-modulith-events-core</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-couchbase</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-data-couchbase</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-transaction</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-couchbase-test</artifactId>
<scope>test</scope>
</dependency>

<!-- Testcontainers -->

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-couchbase</artifactId>
<scope>test</scope>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
* Copyright 2026 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.modulith.events.couchbase;

import org.jspecify.annotations.Nullable;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.PersistenceCreator;
import org.springframework.data.couchbase.core.mapping.Document;
import org.springframework.data.couchbase.core.mapping.Field;
import org.springframework.data.couchbase.repository.Collection;
import org.springframework.util.Assert;

import java.time.Instant;
import java.util.UUID;

import static org.springframework.modulith.events.EventPublication.*;
import static org.springframework.modulith.events.couchbase.CouchbaseEventPublicationRepository.*;

/**
* A CouchBase Document to represent event publications.
*
* @author Oliver Drotbohm
* @author Alexandre Vigneron
*/
@Document
@Collection(value = BASE_COLLECTION)
class CouchbaseEventPublication {

@Id
final UUID id;
@Field
final Instant publicationDate;
@Field
final String listenerId;
@Field
final Object event;
@Field
@Nullable
final Instant lastResubmissionDate;
@Field
final int completionAttempts;

@Field
@Nullable
Instant completionDate;
@Field
Status status;

/**
* Creates a new {@link CouchbaseEventPublication} for the given id, publication date, listener id, event and completion
* date.
*
* @param id must not be {@literal null}.
* @param publicationDate must not be {@literal null}.
* @param listenerId must not be {@literal null} or empty.
* @param event must not be {@literal null}.
* @param completionDate can be {@literal null}.
* @param status can be {@literal null}.
* @param lastResubmissionDate can be {@literal null}.
*/
@PersistenceCreator
public CouchbaseEventPublication(UUID id, Instant publicationDate, String listenerId, Object event,
@Nullable Instant completionDate, @Nullable Status status,
@Nullable Instant lastResubmissionDate, int completionAttempts) {
Assert.notNull(id, "Id must not be null!");
Assert.notNull(publicationDate, "Publication date must not be null!");
Assert.notNull(listenerId, "Listener id must not be null!");
Assert.notNull(event, "Event must not be null!");

this.id = id;
this.publicationDate = publicationDate;
this.listenerId = listenerId;
this.event = event;
this.completionDate = completionDate;
this.status = status != null ? status : completionDate != null ? Status.COMPLETED : Status.PROCESSING;
this.lastResubmissionDate = lastResubmissionDate;
this.completionAttempts = completionAttempts;
}

/**
* Marks the publication as completed at the given {@link Instant}.
*
* @param instant must not be {@literal null}.
* @return will never be {@literal null}.
*/
CouchbaseEventPublication markCompleted(Instant instant) {

Assert.notNull(instant, "Instant must not be null!");

this.completionDate = instant;
this.status = Status.COMPLETED;

return this;
}

/**
* Marks the publication as failed.
*
* @return will never be {@literal null}.
*/
CouchbaseEventPublication markFailed() {
this.status = Status.FAILED;

return this;
}

/**
* Marks the publication as resubmitted at the given {@link Instant}.
*
* @param instant must not be {@literal null}.
* @return will never be {@literal null}.
*/
CouchbaseEventPublication markResubmitted(Instant instant) {
Assert.notNull(instant, "Instant must not be null!");

return new CouchbaseEventPublication(
id, publicationDate, listenerId, event, completionDate,
Status.RESUBMITTED, instant, this.completionAttempts + 1
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2026 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.modulith.events.couchbase;

import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.data.couchbase.core.CouchbaseTemplate;
import org.springframework.modulith.events.config.EventPublicationAutoConfiguration;
import org.springframework.modulith.events.config.EventPublicationConfigurationExtension;
import org.springframework.modulith.events.support.CompletionMode;

/**
* Autoconfiguration for Couchbase event publication repository.
*
* @author Oliver Drotbohm
* @author Alexandre Vigneron
*/
@AutoConfiguration
@AutoConfigureBefore(EventPublicationAutoConfiguration.class)
class CouchbaseEventPublicationAutoConfiguration implements EventPublicationConfigurationExtension {

@Bean
CouchbaseEventPublicationRepository couchBaseEventPublicationRepository(CouchbaseTemplate template,
Environment environment) {
return new CouchbaseEventPublicationRepository(template, CompletionMode.from(environment));
}
}
Loading
Loading