Java SDK
The SLIM Java SDK (io.agntcy.slim:slim-bindings-java) provides an idiomatic Java API for building applications on SLIM. Bindings are generated from the same Rust core as every other language binding via uniffi-bindgen-java, with synchronous methods and CompletableFuture-based async variants. The generated code calls the native library through the Java Foreign Function & Memory API (Project Panama).
Requirements
| Runtime | JDK 21, run with --enable-preview |
| Package | slim-bindings-java on Maven Central |
| Build tools | Maven 3.8+ |
| Examples | java/examples in slim-bindings |
The Maven artifact bundles native libraries for Linux, macOS, and Windows on x64 and arm64, one per platform directory at the root of the JAR (for example darwin-aarch64/libslim_bindings.dylib).
JVM flags
The bindings are compiled for Java 21 with preview features enabled (the Foreign Function & Memory API is a preview API in Java 21), so code that uses them must be compiled with --enable-preview (javac rejects classes that use preview features otherwise) and run on JDK 21 started with --enable-preview. The examples also pass --add-opens=java.base/java.lang=ALL-UNNAMED and --add-opens=java.base/java.lang.reflect=ALL-UNNAMED.
The native library is loaded with System.loadLibrary("slim_bindings"), which does not look inside the JAR. Extract the library for your platform and point the JVM at it, either with -Djava.library.path=<dir containing libslim_bindings> or with an absolute path via -Duniffi.component.slim_bindings.libraryOverride=/path/to/libslim_bindings.dylib.
For example:
java --enable-preview \
--add-opens=java.base/java.lang=ALL-UNNAMED \
--add-opens=java.base/java.lang.reflect=ALL-UNNAMED \
-Djava.library.path=/path/to/native/darwin-aarch64 \
-jar my-app.jar
With Maven exec:java, which runs in Maven's own JVM, put the flags in .mvn/jvm.config as the examples do.
Installation
Add to your pom.xml:
<dependency>
<groupId>io.agntcy.slim</groupId>
<artifactId>slim-bindings-java</artifactId>
<version>3.3.9</version>
</dependency>
Compile with preview features enabled:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<release>21</release>
<compilerArgs>
<arg>--enable-preview</arg>
</compilerArgs>
</configuration>
</plugin>
dependencies {
implementation("io.agntcy.slim:slim-bindings-java:3.3.9")
}
tasks.withType<JavaCompile> {
options.compilerArgs.add("--enable-preview")
}
tasks.withType<JavaExec> {
jvmArgs("--enable-preview")
}
tasks.withType<Test> {
jvmArgs("--enable-preview")
}
Getting Started
The SDK tutorials build a full application step by step — initialising the service, connecting to a node, creating an app, opening sessions, receiving messages, and adding persistence — with Java snippets shown alongside every other binding.
Start with Connecting to SLIM.
API Overview
| Class | Description |
|---|---|
SlimBindings |
Static entry point for initialisation and global service access |
Service |
Manages connections and creates apps |
App |
Application handle for sessions, subscriptions, and routing |
Session |
Session for sending and receiving messages |
Name |
Identity in org/namespace/app format |
ReceivedMessage |
Received message with payload() (bytes) and context metadata |
SessionConfig |
Session configuration (type, MLS, retries) |
ClientConfig |
Client connection configuration (endpoint, TLS, transport auth) |
ServerConfig |
Server listen configuration (endpoint, TLS, transport auth) |
OidcConfig |
OIDC transport authentication settings |
OidcPolicyConfig |
Claim-based access policy (Cel, Rego, RegoFile) |
Async variants (*Async) returning CompletableFuture are available for all operations. With Java 21 virtual threads, blocking on .get() or .join() is inexpensive.
Session Configuration
SessionConfig sessionConfig = new SessionConfig(
SessionType.POINT_TO_POINT,
null, // maxRetries — null uses the SLIM default
null, // interval — null uses the SLIM default
Map.of(), // metadata
new MlsSettings(100, null));
Session session = app.createSessionAndWait(sessionConfig, remoteName);
The constructor is positional and takes all five fields. MlsSettings takes the header-integrity validation percentage and an optional replay-protection cache size; passing null in its place disables MLS.
Transport Authentication
Separate from the app identity passed to createAppWithSecret, the gRPC connection to a SLIM node can carry its own credentials via ClientConfig.setAuth.
OIDC (client credentials)
ClientConfig config = SlimBindings.newInsecureClientConfig("http://127.0.0.1:46357");
config.setAuth(new ClientAuthenticationConfig.Oidc(new OidcConfig(
"https://auth.example.com", // issuerUrl
"my-client", // clientId
"s3cr3t", // clientSecret
null, null, null, null, // audience, refreshToken, refreshTokenFile, accessTokenFile
"openid profile", // scope
Duration.ofSeconds(30), // timeout
null, null, null))); // jwksTtl, claimCacheTtl, policy
Long connId = service.connect(config);
For the refresh-token flow, set refreshToken (or refreshTokenFile, which is rewritten in place as tokens rotate) instead of clientSecret.
OIDC (server verification)
ServerConfig config = SlimBindings.newInsecureServerConfig("127.0.0.1:46357");
config.setAuth(new ServerAuthenticationConfig.Oidc(new OidcConfig(
"https://auth.example.com",
null, null,
"slim", // audience — required for verification
null, null, null, null, null,
Duration.ofHours(1), // jwksTtl
Duration.ofMinutes(1), // claimCacheTtl
new OidcPolicyConfig.Cel("\"admin\" in claims.groups"))));
service.runServerAsync(config).get();
policy accepts OidcPolicyConfig.Cel, OidcPolicyConfig.Rego (which must define package slim.auth with default allow = false), or OidcPolicyConfig.RegoFile.
JSON configuration
SlimBindings.newConfigFromJson accepts a full gRPC client config covering TLS material, backoff, and every authentication mode:
{
"endpoint": "http://127.0.0.1:46357",
"tls": { "insecure": true },
"auth": {
"type": "oidc",
"issuer_url": "https://auth.example.com",
"client_id": "my-client",
"client_secret": "s3cr3t",
"audience": "slim",
"policy": { "cel": "\"admin\" in claims.groups" }
}
}
The schema matches the client configuration schema in the slim repository.
SLIMRPC
The Java SDK includes SLIMRPC support for Protobuf-based RPC over SLIM. Install the protoc-gen-slimrpc-java plugin and add it to your buf.gen.yaml alongside the standard Java protobuf plugin. See the SLIMRPC Compiler and the Serving and Client tutorials.
Generated code lives in the io.agntcy.slim.bindings.slimrpc package.
Examples
The slim-bindings/java directory includes complete working examples:
| Example | Description |
|---|---|
PointToPoint |
1:1 messaging with request/reply |
Group |
Group sessions with moderator/participant roles |
Server |
SLIM data plane server |
examples/slimrpc/simple |
Protobuf RPC over SLIM |
Point-to-point:
cd java
task examples:p2p:alice # Receiver
task examples:p2p:no-mls:bob # Sender (in another terminal)
SLIMRPC (requires a running SLIM node and generated proto code):
task examples:rpc:server
task examples:rpc:client
Platform Support
| Platform | Architecture | JAR directory |
|---|---|---|
| Linux | x86_64 | linux-x86-64 |
| Linux | aarch64 | linux-aarch64 |
| macOS | x86_64 | darwin-x86-64 |
| macOS | aarch64 | darwin-aarch64 |
| Windows | x86_64 | win32-x86-64 |
| Windows | aarch64 | win32-aarch64 |
Building from Source
To build the Java SDK from the slim-bindings repository:
git clone https://github.com/agntcy/slim-bindings
cd slim-bindings/java
task generate # regenerate Java bindings from Rust artifacts
task build
task install # install to local Maven repository
See the java README for the full list of development tasks.
Next Steps
- Connecting to SLIM — Initialise the service and connect to a node
- Creating an App — Register an application identity
- Creating a Session — Open a point-to-point or group session
- SLIMRPC — Protobuf RPC over SLIM