Caution
⚠️ This is a legacy SDK. It is deprecated.
🚫 Do not start new projects with stream-chat-java.
✅ Use stream-sdk-java (Maven io.getstream:stream-sdk-java) instead. It covers Chat, Video, Moderation and Feeds in one SDK.
🔁 Already using stream-chat-java? Follow the migration guide to move your code.
Legacy Java API client for Stream Chat, a service for building chat applications.
Explore the docs »
JavaDoc
·
Code Samples
·
Report Bug
·
Request Feature
📝 About Stream
You can sign up for a Stream account at our Get Started page.
You can use this library to access chat API endpoints server-side.
For the client-side integrations (web and mobile) have a look at the JavaScript, iOS and Android SDK libraries (docs).
⚙️ Installation
The Stream chat Java SDK requires Java 11+. It supports latest LTS.
The Stream chat Java SDK is compatible with Groovy, Scala, Kotlin and Clojure.
Repository
Releases are published to the Stream Maven repository. Add it next to Maven Central.
Gradle
repositories {
mavenCentral()
maven { url "https://stream-io-repo.com" }
}
Maven
<repositories>
<repository>
<id>stream</id>
<url>https://stream-io-repo.com</url>
</repository>
</repositories>
Leiningen
:repositories [["stream" "https://stream-io-repo.com"]]
Installation for Java
Gradle
dependencies {
implementation "io.getstream:stream-chat-java:$stream_version"
}
Maven
<dependency>
<groupId>io.getstream</groupId>
<artifactId>stream-chat-java</artifactId>
<version>$stream_version</version>
</dependency>
Installation for Groovy
Gradle
dependencies {
implementation 'io.getstream:stream-chat-java:$stream_version'
}
You can see an example project at GetStream/stream-chat-groovy-example.
Installation for Scala
Gradle
dependencies {
implementation 'io.getstream:stream-chat-java:$stream_version'
}
You can see an example project at GetStream/stream-chat-scala-example.
Installation for Kotlin
Gradle
dependencies {
implementation("io.getstream:stream-chat-java:$stream_version")
}
You can see an example project at GetStream/stream-chat-kotlin-example.
Installation for Clojure
Leiningen
:dependencies [[io.getstream/stream-chat-java "$stream_version"]]
You can see an example project at GetStream/stream-chat-clojure-example.
🔀 Dependencies
This SDK uses lombok (code generation), retrofit (http client), jackson (json) and jjwt (jwt).
You can find the exact versions in build.gradle.
🥷🏿 Shadowed version
If you have conflicts with our dependencies, you can use the shadowed (shaded) version of the library:
io.getstream:stream-chat-java-all:1.26.2
✨ Getting started
Configuration
To configure the SDK you need to provide required properties
| Property |
ENV |
Default |
Required |
| io.getstream.chat.apiKey |
STREAM_KEY |
- |
Yes |
| io.getstream.chat.apiSecret |
STREAM_SECRET |
- |
Yes |
| io.getstream.chat.timeout |
STREAM_CHAT_TIMEOUT |
20000 |
No |
| io.getstream.chat.connectTimeout |
STREAM_CHAT_CONNECT_TIMEOUT |
20000 |
No |
| io.getstream.chat.readTimeout |
STREAM_CHAT_READ_TIMEOUT |
20000 |
No |
| io.getstream.chat.writeTimeout |
STREAM_CHAT_WRITE_TIMEOUT |
20000 |
No |
| io.getstream.chat.url |
STREAM_CHAT_URL |
https://chat.stream-io-api.com |
No |
| io.getstream.chat.connectionPool.maxIdleConnections |
STREAM_CHAT_CONNECTION_POOL_MAX_IDLE_CONNECTIONS |
10 |
No |
| io.getstream.chat.connectionPool.keepAliveDurationMs |
STREAM_CHAT_CONNECTION_POOL_KEEP_ALIVE_DURATION_MS |
118000 |
No |
| io.getstream.chat.dispatcher.maxRequests |
STREAM_CHAT_DISPATCHER_MAX_REQUESTS |
128 |
No |
| io.getstream.chat.dispatcher.maxRequestsPerHost |
STREAM_CHAT_DISPATCHER_MAX_REQUESTS_PER_HOST |
10 |
No |
You can also use your own CDN by creating an implementation of FileHandler and setting it this way
Message.fileHandlerClass = MyFileHandler.class
All setup must be done prior to any request to the API.
You can also tune the underlying OkHttp connection pool explicitly:
var properties = new Properties();
properties.put(DefaultClient.API_KEY_PROP_NAME, "<api-key>");
properties.put(DefaultClient.API_SECRET_PROP_NAME, "<api-secret>");
properties.put(DefaultClient.DISPATCHER_MAX_REQUESTS_PROP_NAME, "128");
properties.put(DefaultClient.DISPATCHER_MAX_REQUESTS_PER_HOST_PROP_NAME, "32");
properties.put(DefaultClient.CONNECTION_POOL_MAX_IDLE_CONNECTIONS_PROP_NAME, "20");
properties.put(DefaultClient.CONNECTION_POOL_KEEP_ALIVE_DURATION_PROP_NAME, "59000");
properties.put(DefaultClient.API_CONNECT_TIMEOUT_PROP_NAME, "10000");
properties.put(DefaultClient.API_READ_TIMEOUT_PROP_NAME, "30000");
properties.put(DefaultClient.API_WRITE_TIMEOUT_PROP_NAME, "30000");
properties.put(DefaultClient.API_TIMEOUT_PROP_NAME, "30000");
var client = new DefaultClient(properties);
client.setDispatcher(128, 32);
client.setConnectionPool(20, Duration.ofSeconds(59));
client.setTimeouts(
Duration.ofSeconds(10),
Duration.ofSeconds(30),
Duration.ofSeconds(30),
Duration.ofSeconds(30));
DefaultClient.setInstance(client);
Or configure the same values through options:
var options =
DefaultClient.HttpClientOptions.builder()
.dispatcher(128, 32)
.connectionPool(20, Duration.ofSeconds(59))
.connectTimeout(Duration.ofSeconds(10))
.readTimeout(Duration.ofSeconds(30))
.writeTimeout(Duration.ofSeconds(30))
.callTimeout(Duration.ofSeconds(30))
.build();
var client = new DefaultClient(properties, options);
High traffic
For high traffic backends, a good starting point is:
var options =
DefaultClient.HttpClientOptions.builder()
.dispatcher(128, 32)
.connectionPool(20, Duration.ofSeconds(59))
.connectTimeout(Duration.ofSeconds(10))
.readTimeout(Duration.ofSeconds(30))
.writeTimeout(Duration.ofSeconds(30))
.callTimeout(Duration.ofSeconds(30))
.build();
Start there and load test. In practice, dispatcher.maxRequests and
dispatcher.maxRequestsPerHost usually affect throughput more than connection-pool size.
Print Chat app configuration
| Java |
System.out.println(App.get().request());
|
| Groovy |
println App.get().request()
|
| Scala |
|
| Kotlin |
println(App.get().request())
|
| Clojure |
println (.request (App/get))
|
📚 Code examples
Head over to DOCS.md for code snippets.
🙋 FAQ
- If you get this exception:
java.lang.ClassNotFoundException: io.jsonwebtoken.SignatureAlgorithm:
See shadowed version.
✍️ Contributing
We welcome code changes that improve this library or fix a problem, please make sure to follow all best practices and add tests if applicable before submitting a Pull Request on Github. We are very happy to merge your code in the official repository. Make sure to sign our Contributor License Agreement (CLA) first. See our license file for more details.
Head over to CONTRIBUTING.md for some development tips.
🧑💻 We are hiring!
We've recently closed a $38 million Series B funding round and we keep actively growing.
Our APIs are used by more than a billion end-users, and you'll have a chance to make a huge impact on the product within a team of the strongest engineers all over the world.
Check out our current openings and apply via Stream's website.