Skip to content

Repository files navigation

Note:stream-sdk-java is the new full-product SDK for Stream, covering Chat, Video, Moderation, and Feeds with long-term support.

stream-chat-java is now in maintenance mode. It will continue to receive critical fixes and requested features, so it is safe to keep using. However, we encourage existing users to migrate when convenient and strongly recommend that new projects start with stream-sdk-java.

Check out the Migration Guide for side-by-side examples covering common use cases.

Official Java SDK for Stream Chat

Maven Centralbuild

Official 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.

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

PropertyENVDefaultRequired
io.getstream.chat.apiKeySTREAM_KEY-Yes
io.getstream.chat.apiSecretSTREAM_SECRET-Yes
io.getstream.chat.timeoutSTREAM_CHAT_TIMEOUT20000No
io.getstream.chat.connectTimeoutSTREAM_CHAT_CONNECT_TIMEOUT20000No
io.getstream.chat.readTimeoutSTREAM_CHAT_READ_TIMEOUT20000No
io.getstream.chat.writeTimeoutSTREAM_CHAT_WRITE_TIMEOUT20000No
io.getstream.chat.urlSTREAM_CHAT_URLhttps://chat.stream-io-api.comNo
io.getstream.chat.connectionPool.maxIdleConnectionsSTREAM_CHAT_CONNECTION_POOL_MAX_IDLE_CONNECTIONS10No
io.getstream.chat.connectionPool.keepAliveDurationMsSTREAM_CHAT_CONNECTION_POOL_KEEP_ALIVE_DURATION_MS118000No
io.getstream.chat.dispatcher.maxRequestsSTREAM_CHAT_DISPATCHER_MAX_REQUESTS128No
io.getstream.chat.dispatcher.maxRequestsPerHostSTREAM_CHAT_DISPATCHER_MAX_REQUESTS_PER_HOST10No

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:

varproperties = newProperties();
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");
varclient = newDefaultClient(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:

varoptions =
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();
varclient = newDefaultClient(properties, options);

High traffic

For high traffic backends, a good starting point is:

varoptions =
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
printlnApp.get().request()
Scala
println(App.get.request)
Kotlin
println(App.get().request())
Clojure
println (.request (App/get))

📚 Code examples

Head over to DOCS.md for code snippets.

🙋 FAQ

  1. 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.

About

Official Stream Chat API client for Java (maintenance mode). For new projects, see stream-sdk-java.

Topics

Resources

Contributing

Security policy

Stars

24 stars

Watchers

29 watching

Forks

Releases

Used by

Contributors

Languages