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:
importio.ably.lib.realtime.AblyRealtime;
importio.ably.lib.types.ClientOptions;
ClientOptionsoptions = newClientOptions(apiKey);
AblyRealtimerealtime = newAblyRealtime(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 clientClientOptionsoptions = newClientOptions("your-ably-api-key");
options.clientId = "me";
AblyRealtimerealtimeClient = newAblyRealtime(options);
// Wait for connection to be establishedrealtimeClient.connection.on(ConnectionEvent.connected, connectionStateChange -> {
System.out.println("Connected to Ably");
// Get a reference to the 'test-channel' channelChannelchannel = realtimeClient.channels.get("test-channel");
// Subscribe to all messages published to this channelchannel.subscribe(message -> {
System.out.println("Received message: " + message.data);
});
// Publish a test message to the channelchannel.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:
importio.ably.lib.realtime.AblyRealtime;
importio.ably.lib.rest.AblyRest;
importio.ably.lib.transport.Defaults;
importio.ably.lib.types.ClientOptions;
importio.ably.lib.types.ProxyOptions;
importio.ably.lib.http.HttpAuth;
publicclassAblyWithProxy {
publicstaticvoidmain(String[] args) throwsException {
// Configure Ably Client optionsClientOptionsoptions = newClientOptions();
// Setup proxy settingsProxyOptionsproxy = newProxyOptions();
proxy.host = "your-proxy-host"; // Replace with your proxy hostproxy.port = 8080; // Replace with your proxy port// Optional: If the proxy requires authenticationproxy.username = "your-username"; // Replace with proxy usernameproxy.password = "your-password"; // Replace with proxy passwordproxy.prefAuthType = HttpAuth.Type.BASIC; // Choose your preferred authentication type (e.g., BASIC or DIGEST)// Attach the proxy settings to the client optionsoptions.proxy = proxy;
// Create an instance of Ably using the configured optionsAblyRestably = newAblyRest(options);
// Alternatively, for real-time connectionsAblyRealtimeablyRealtime = newAblyRealtime(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.
