Official Java client SDK for Apache Iggy message streaming.
This is part of the Apache Iggy monorepo. For the main project, see the root repository.
These examples target server 0.9.0. SDK 0.9.0 is on Maven Central and works with server 0.9.0. The older 0.8.0 artifact speaks the previous TCP protocol and does not work with server 0.9.0. Java 17 or newer is required.
Add the dependency to your project:
Gradle:
implementation 'org.apache.iggy:iggy:0.9.0'
Maven:
<dependency> <groupId>org.apache.iggy</groupId> <artifactId>iggy</artifactId> <version>0.9.0</version> </dependency>
See Maven Central for all published versions.
Development builds of the next release carry the version 0.9.1-SNAPSHOT. Get them from the ASF snapshot repository:
Gradle:
repositories { mavenCentral() maven { url = uri("https://repository.apache.org/content/repositories/snapshots/") } } dependencies { implementation 'org.apache.iggy:iggy:0.9.1-SNAPSHOT' }
Maven:
<repositories> <repository> <id>apache-snapshots</id> <url>https://repository.apache.org/content/repositories/snapshots/</url> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <dependencies> <dependency> <groupId>org.apache.iggy</groupId> <artifactId>iggy</artifactId> <version>0.9.1-SNAPSHOT</version> </dependency> </dependencies>
Iggy.tcpClientBuilder() handles the routing and the session for you. Over TCP and TCP/TLS, the client keeps the consumer group membership on the coordinator. It polls each partition through a separate connection to the primary of that partition.
Start the server with the example prerequisites and matching credentials. The following snippets show alternative clients. Close a blocking client with close() or an async client with close().join() when finished.
import org.apache.iggy.Iggy; // Create and connect with auto-login var client = Iggy.tcpClientBuilder() .blocking() .host("localhost") .port(8090) .credentials("iggy", "iggy") .buildAndLogin(); // Or build, connect, and login separately var client = Iggy.tcpClientBuilder() .blocking() .host("localhost") .port(8090) .build(); client.connect(); client.users().login("iggy", "iggy");
import org.apache.iggy.Iggy; // Create async client var asyncClient = Iggy.tcpClientBuilder() .async() .host("localhost") .port(8090) .credentials("iggy", "iggy") .buildAndLogin() .join(); // Or with manual connect and login var asyncClient = Iggy.tcpClientBuilder() .async() .host("localhost") .build(); asyncClient.connect().join(); asyncClient.users().login("iggy", "iggy").join();
import org.apache.iggy.Iggy; // Using URL var httpClient = Iggy.httpClientBuilder() .blocking() .url("http://localhost:3000") .credentials("iggy", "iggy") .buildAndLogin(); // Using host/port var httpClient = Iggy.httpClientBuilder() .blocking() .host("localhost") .port(3000) .credentials("iggy", "iggy") .buildAndLogin();
Both TCP and HTTP clients support TLS:
// TCP with TLS var secureClient = Iggy.tcpClientBuilder() .blocking() .host("iggy-server.example.com") .port(8090) .enableTls() .tlsCertificate("/path/to/ca.pem") // Optional custom CA .credentials("admin", "secret") .buildAndLogin(); // HTTPS var secureHttpClient = Iggy.httpClientBuilder() .blocking() .host("iggy-server.example.com") .port(443) .enableTls() .credentials("admin", "secret") .buildAndLogin();
The client builders support additional configuration:
var client = Iggy.tcpClientBuilder() .blocking() .host("localhost") .port(8090) .connectionTimeout(Duration.ofSeconds(10)) .requestTimeout(Duration.ofSeconds(30)) .retryPolicy(RetryPolicy.exponentialBackoff()) .credentials("iggy", "iggy") .buildAndLogin();
Each TCP client drives a single connection, so by default it creates an event loop group with one thread. An application that opens many clients can instead register them all on one caller-owned group. The clients never shut that group down. Close the clients first, then shut the group down:
var group = new MultiThreadIoEventLoopGroup(2, NioIoHandler.newFactory()); var producer = Iggy.tcpClientBuilder() .blocking() .eventLoopGroup(group) .credentials("iggy", "iggy") .buildAndLogin(); var consumer = Iggy.tcpClientBuilder() .blocking() .eventLoopGroup(group) .credentials("iggy", "iggy") .buildAndLogin(); // ... later producer.close(); consumer.close(); group.shutdownGracefully();
Do not block in a completion callback. Callbacks run on the group's loops, so a blocked callback stalls every client that shares the group.
// Get SDK version String version = Iggy.version(); // e.g., "0.9.0" // Get detailed version info IggyVersion info = Iggy.versionInfo(); info.getVersion(); // Version string info.getBuildTime(); // Build timestamp info.getGitCommit(); // Git commit hash info.getUserAgent(); // User-Agent string for HTTP
The SDK‘s custom exception types inherit from IggyException. When you join a failed future, the cause can come back inside a CompletionException. The HTTP client’s close() method declares IOException. Handle these two boundaries as well as the specific SDK errors.
See the Java Examples directory for runnable applications demonstrating the SDK:
The examples README describes blocking and async clients, CompletableFuture patterns, and thread pool management.
For Apache Flink integration, see the Flink Connector Library.
This project uses the Gradle Wrapper. Due to Apache Software Foundation policy, the gradle-wrapper.jar binary is not checked into the repository. Instead, the gradlew script automatically downloads it on first run.
# Build the project ./gradlew build # Run tests ./gradlew test
The wrapper script will:
gradle-wrapper.jar from the official Gradle repository if missingNo manual Gradle installation is required.
Note: Only the Unix shell wrapper (gradlew) is provided. On Windows, use WSL or Git Bash, or install Gradle manually.
Before opening a pull request:
./gradlew spotlessApply./gradlew checkassertThat(...)) instead of JUnit assertions.These steps keep the code style compliant and make sure that all tests and checkstyle validations pass.