Build any realtime experience using Ably’s Pub/Sub Java SDK. Supported on all popular platforms and frameworks, including Kotlin and Android.
Ably Pub/Sub provides flexible APIs that deliver features such as pub-sub messaging, message history, presence, and push notifications. Utilizing Ably’s realtime messaging platform, applications benefit from its highly performant, reliable, and scalable infrastructure.
Find out more:
Everything you need to get started with Ably:
Ably aims to support a wide range of platforms. If you experience any compatibility issues, open an issue in the repository or contact Ably support.
The following platforms are supported:
Platform | Support |
---|---|
Java | >= 1.8 (JRE 8 or later) |
Kotlin | All versions (>= 1.0 supported), but we recommend >= 1.8 for best compatibility. |
Android | >=4.4 (API level 19) |
Important
SDK versions < 1.2.35 will be deprecated from November 1, 2025.
The Java SDK is available as a Maven dependency. To get started with your project, install the package:
<dependency>
<groupId>io.ably</groupId>
<artifactId>ably-java</artifactId>
<version>1.2.54</version>
</dependency>
implementation 'io.ably:ably-java:1.2.54'
implementation 'org.slf4j:slf4j-simple:2.0.7'
Run the following to instantiate a client:
import io.ably.lib.realtime.AblyRealtime;
import io.ably.lib.types.ClientOptions;
ClientOptions options = new ClientOptions(apiKey);
AblyRealtime realtime = new AblyRealtime(options);
The following code connects to Ably's realtime messaging service, subscribes to a channel to receive messages, and publishes a test message to that same channel.
// Initialize Ably Realtime client
ClientOptions options = new ClientOptions("your-ably-api-key");
options.clientId = "me";
AblyRealtime realtimeClient = new AblyRealtime(options);
// Wait for connection to be established
realtimeClient.connection.on(ConnectionEvent.connected, connectionStateChange -> {
System.out.println("Connected to Ably");
// Get a reference to the 'test-channel' channel
Channel channel = realtimeClient.channels.get("test-channel");
// Subscribe to all messages published to this channel
channel.subscribe(message -> {
System.out.println("Received message: " + message.data);
});
// Publish a test message to the channel
channel.publish("test-event", "hello world");
});
You can add proxy support to the Ably Java SDK by configuring ProxyOptions
in your client setup, enabling connectivity through corporate firewalls and secured networks.
Proxy support setup details.
To enable proxy support for both REST and Realtime clients in the Ably SDK, use the OkHttp library to handle HTTP requests and WebSocket connections.
Add the following dependency to your build.gradle
file:
dependencies {
runtimeOnly("io.ably:network-client-okhttp:1.2.54")
}
After adding the OkHttp dependency, enable proxy support by specifying proxy settings in the ClientOptions when initializing your Ably client.
The following example sets up a proxy using the Pub/Sub Java SDK:
import io.ably.lib.realtime.AblyRealtime;
import io.ably.lib.rest.AblyRest;
import io.ably.lib.transport.Defaults;
import io.ably.lib.types.ClientOptions;
import io.ably.lib.types.ProxyOptions;
import io.ably.lib.http.HttpAuth;
public class AblyWithProxy {
public static void main(String[] args) throws Exception {
// Configure Ably Client options
ClientOptions options = new ClientOptions();
// Setup proxy settings
ProxyOptions proxy = new ProxyOptions();
proxy.host = "your-proxy-host"; // Replace with your proxy host
proxy.port = 8080; // Replace with your proxy port
// Optional: If the proxy requires authentication
proxy.username = "your-username"; // Replace with proxy username
proxy.password = "your-password"; // Replace with proxy password
proxy.prefAuthType = HttpAuth.Type.BASIC; // Choose your preferred authentication type (e.g., BASIC or DIGEST)
// Attach the proxy settings to the client options
options.proxy = proxy;
// Create an instance of Ably using the configured options
AblyRest ably = new AblyRest(options);
// Alternatively, for real-time connections
AblyRealtime ablyRealtime = new AblyRealtime(options);
// Use the Ably client as usual
}
}
Read the CONTRIBUTING.md guidelines to contribute to Ably.
The CHANGELOG.md contains details of the latest releases for this SDK. You can also view all Ably releases on changelog.ably.com.
For help or technical support, visit Ably's support page or GitHub Issues for community-reported bugs and discussions.