Official Java client library for rstmdb — a distributed state machine database.
- init repo (initial README, .gitignore, LICENSE, etc)
- skeleton of a multinodular gradle project
- module with a java core client
- example hello world applications
- test containers
- SAST (dependency check) security tools in the pipeline
- testing of different JDK versions
- Github pipeline
- maven central publication in the pipeline
- module with a spring boot autoconfig
- documentation (website or wiki)
- Java 11+
- rstmdb server
dependencies {
implementation("com.rstmdb:rstmdb-client:0.1.0")
}dependencies {
implementation 'com.rstmdb:rstmdb-client:0.1.0'
}<dependency>
<groupId>com.rstmdb</groupId>
<artifactId>rstmdb-client</artifactId>
<version>0.1.0</version>
</dependency>import com.rstmdb.client.*;
import com.rstmdb.client.model.*;
import java.util.Map;
try (var client = RstmdbClient.connect("localhost", 7401)) {
// Register a state machine
client.putMachineSync(new PutMachineRequest(
"order", 1,
new MachineDefinition(
new String[]{"created", "paid", "shipped"},
"created",
new Transition[]{
new Transition(new String[]{"created"}, "PAY", "paid", null),
new Transition(new String[]{"paid"}, "SHIP", "shipped", null),
},
null
),
null
));
// Create an instance
var instance = client.createInstanceSync(new CreateInstanceRequest(
"order-001", "order", 1,
Map.of("customer", "alice"),
null
));
// Apply an event
var result = client.applyEventSync(new ApplyEventRequest(
"order-001", "PAY", Map.of("amount", 99.99),
null, null, null, null
));
System.out.println(result.fromState() + " -> " + result.toState());
}All operations are available as both async (CompletableFuture<T>) and sync (*Sync) methods:
| Category | Methods |
|---|---|
| System | ping, getInfo |
| Machines | putMachine, getMachine, listMachines |
| Instances | createInstance, getInstance, listInstances, deleteInstance |
| Events | applyEvent, batch |
| Watch | watchInstance, watchAll |
| WAL | snapshotInstance, walRead, walStats, compact |
var opts = RstmdbOptions.builder()
.auth("bearer-token")
.connectTimeout(Duration.ofSeconds(5))
.requestTimeout(Duration.ofSeconds(15))
.clientName("my-service")
.build();
var client = RstmdbClient.connect("localhost", 7401, opts);// CA certificate
var opts = RstmdbOptions.builder()
.sslContext(RstmdbOptions.createTlsContext(Path.of("ca.pem")))
.build();
// Insecure (development only)
var opts = RstmdbOptions.builder()
.sslContext(RstmdbOptions.insecureTlsContext())
.build();client.ping()
.thenCompose(v -> client.createInstance(request))
.thenCompose(inst -> client.applyEvent(eventRequest))
.thenAccept(result -> System.out.println(result.toState()))
.exceptionally(ex -> {
if (ex.getCause() instanceof RstmdbException re) {
System.err.println("Error: " + re.getErrorCode());
}
return null;
})
.join();var sub = client.watchAllSync(new WatchAllOptions(
true, null, new String[]{"order"}, null, null, null));
for (var event : sub.events()) {
System.out.printf("%s: %s -> %s%n",
event.instanceId(), event.fromState(), event.toState());
}try {
client.applyEventSync(request);
} catch (RstmdbException e) {
if (RstmdbException.isInvalidTransition(e)) {
// handle invalid transition
} else if (e.isRetryable()) {
// safe to retry
}
}- JDK 25
./gradlew build./gradlew test./gradlew clean./gradlew build -x testMIT