Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,44 @@ You can override this behavior by explicitly passing in the API key and secret a
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);
```

You can also pass the same configuration through explicit HTTP options:

```java
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);
```

For high traffic workloads, `dispatcher.maxRequests` and
`dispatcher.maxRequestsPerHost` are usually the first values to tune.

### Simple Example
**Synchronous:**

Expand Down Expand Up @@ -1896,4 +1930,4 @@ Import.createImport(createUrlResponse.getPath(), Import.ImportMode.Upsert);
```java
// signature comes from the HTTP header x-signature
boolean valid = App.verifyWebhook(body, signature)
```
```
70 changes: 69 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,15 @@ To configure the SDK you need to provide required properties
| --------------------------- | ------------------- | ------------------------------ | -------- |
| io.getstream.chat.apiKey | STREAM_KEY | - | Yes |
| io.getstream.chat.apiSecret | STREAM_SECRET | - | Yes |
| io.getstream.chat.timeout | STREAM_CHAT_TIMEOUT | 10000 | No |
| 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

Expand All @@ -141,6 +148,67 @@ 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:

```java
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:

```java
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:

```java
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

<table>
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
id 'io.github.gradle-nexus.publish-plugin' version '2.0.0'
id 'com.diffplug.spotless' version '6.25.0'
id 'org.barfuin.gradle.jacocolog' version '3.1.0'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'com.gradleup.shadow' version '8.3.10'
id 'io.freefair.lombok' version '8.4'
}

Expand Down Expand Up @@ -33,8 +33,8 @@ dependencies {
// define any required OkHttp artifacts without version
implementation("com.squareup.okhttp3:okhttp")

implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-jackson:2.9.0'
implementation 'com.squareup.retrofit2:retrofit:2.12.0'
implementation 'com.squareup.retrofit2:converter-jackson:2.12.0'
implementation 'io.jsonwebtoken:jjwt-api:0.12.5'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.12.5'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.12.5'
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/io/getstream/chat/java/models/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ public static class DeviceError {

@Builder
@Getter
@EqualsAndHashCode
@EqualsAndHashCode(callSuper = false)
public static class AsyncModerationCallback {
@Nullable
@JsonProperty("mode")
Expand All @@ -599,7 +599,7 @@ public static class AsyncModerationCallback {

@Builder
@Getter
@EqualsAndHashCode
@EqualsAndHashCode(callSuper = false)
public static class AsyncModerationConfigRequestObject {
@Nullable
@JsonProperty("callback")
Expand All @@ -612,7 +612,7 @@ public static class AsyncModerationConfigRequestObject {

@Builder
@Getter
@EqualsAndHashCode
@EqualsAndHashCode(callSuper = false)
public static class FileUploadConfigRequestObject {

@Nullable
Expand Down Expand Up @@ -644,7 +644,7 @@ public static FileUploadConfigRequestObject buildFrom(

@Builder
@Getter
@EqualsAndHashCode
@EqualsAndHashCode(callSuper = false)
public static class APNConfigRequestObject {
@Nullable
@JsonProperty("development")
Expand Down Expand Up @@ -690,7 +690,7 @@ public static APNConfigRequestObject buildFrom(@Nullable APNConfig aPNConfig) {

@Builder
@Getter
@EqualsAndHashCode
@EqualsAndHashCode(callSuper = false)
public static class FirebaseConfigRequestObject {
@Nullable
@JsonProperty("server_key")
Expand Down Expand Up @@ -720,7 +720,7 @@ public static FirebaseConfigRequestObject buildFrom(@Nullable FirebaseConfig fir

@Builder
@Getter
@EqualsAndHashCode
@EqualsAndHashCode(callSuper = false)
public static class HuaweiConfigRequestObject {
@Nullable
@JsonProperty("id")
Expand All @@ -733,7 +733,7 @@ public static class HuaweiConfigRequestObject {

@Builder
@Getter
@EqualsAndHashCode
@EqualsAndHashCode(callSuper = false)
public static class PushConfigRequestObject {
@Nullable
@JsonProperty("version")
Expand Down Expand Up @@ -764,7 +764,7 @@ protected Call<ListPushProviderResponse> generateCall(Client client) {
}

@Getter
@EqualsAndHashCode
@EqualsAndHashCode(callSuper = false)
public static class DeletePushProviderRequest extends StreamRequest<StreamResponseObject> {
private String providerType;
private String name;
Expand All @@ -785,7 +785,7 @@ protected Call<StreamResponseObject> generateCall(Client client) {
builderMethodName = "",
buildMethodName = "internalBuild")
@Getter
@EqualsAndHashCode
@EqualsAndHashCode(callSuper = false)
public static class AppUpdateRequestData {
@Nullable
@JsonProperty("disable_auth_checks")
Expand Down Expand Up @@ -976,7 +976,7 @@ public boolean equals(Object o) {

@Builder
@Getter
@EqualsAndHashCode
@EqualsAndHashCode(callSuper = false)
@NoArgsConstructor
@AllArgsConstructor
public static class AppGetRateLimitsRequest extends StreamRequest<AppGetRateLimitsResponse> {
Expand Down Expand Up @@ -1008,7 +1008,7 @@ protected Call<AppGetRateLimitsResponse> generateCall(Client client) {
builderMethodName = "",
buildMethodName = "internalBuild")
@Getter
@EqualsAndHashCode
@EqualsAndHashCode(callSuper = false)
public static class AppCheckSqsRequestData {
@Nullable
@JsonProperty("sqs_url")
Expand All @@ -1035,7 +1035,7 @@ protected Call<AppCheckSqsResponse> generateCall(Client client) {
builderMethodName = "",
buildMethodName = "internalBuild")
@Getter
@EqualsAndHashCode
@EqualsAndHashCode(callSuper = false)
public static class AppCheckSnsRequestData {
@Nullable
@JsonProperty("sns_topic_arn")
Expand All @@ -1062,7 +1062,7 @@ protected Call<AppCheckSnsResponse> generateCall(Client client) {
builderMethodName = "",
buildMethodName = "internalBuild")
@Getter
@EqualsAndHashCode
@EqualsAndHashCode(callSuper = false)
public static class AppCheckPushRequestData {
@Nullable
@JsonProperty("message_id")
Expand Down Expand Up @@ -1110,7 +1110,7 @@ protected Call<AppCheckPushResponse> generateCall(Client client) {

@AllArgsConstructor
@Getter
@EqualsAndHashCode
@EqualsAndHashCode(callSuper = false)
public static class AppRevokeTokensRequest extends StreamRequest<StreamResponseObject> {
@Nullable private Date revokeTokensIssuedBefore;

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/io/getstream/chat/java/models/Blocklist.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class Blocklist {
builderMethodName = "",
buildMethodName = "internalBuild")
@Getter
@EqualsAndHashCode
@EqualsAndHashCode(callSuper = false)
public static class BlocklistCreateRequestData {
@Nullable
@JsonProperty("name")
Expand All @@ -58,7 +58,7 @@ protected Call<StreamResponseObject> generateCall(Client client) {

@RequiredArgsConstructor
@Getter
@EqualsAndHashCode
@EqualsAndHashCode(callSuper = false)
public static class BlocklistGetRequest extends StreamRequest<BlocklistGetResponse> {
@NotNull private String name;

Expand All @@ -73,7 +73,7 @@ protected Call<BlocklistGetResponse> generateCall(Client client) {
builderMethodName = "",
buildMethodName = "internalBuild")
@Getter
@EqualsAndHashCode
@EqualsAndHashCode(callSuper = false)
public static class BlocklistUpdateRequestData {
@Nullable
@JsonProperty("words")
Expand All @@ -95,7 +95,7 @@ protected Call<StreamResponseObject> generateCall(Client client) {

@RequiredArgsConstructor
@Getter
@EqualsAndHashCode
@EqualsAndHashCode(callSuper = false)
public static class BlocklistDeleteRequest extends StreamRequest<StreamResponseObject> {
@NotNull private String name;

Expand Down
Loading
Loading