Skip to content

Commit b2d0761

Browse files
committed
solution: enable load-balancing by default
1 parent 2c600b3 commit b2d0761

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

build.gradle

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import org.gradle.testing.jacoco.tasks.JacocoReport
2-
31
buildscript {
42
repositories {
53
mavenLocal()
@@ -27,7 +25,7 @@ if (System.getenv("ENABLE_GCP") == "true") {
2725
}
2826

2927
group = 'io.emeraldpay'
30-
version = '0.12-alpha.3'
28+
version = '0.12-alpha.4'
3129

3230
java {
3331
sourceCompatibility = JavaVersion.VERSION_1_8
@@ -160,4 +158,4 @@ task coverageReport(type: JacocoReport) {
160158
csv.enabled false
161159
html.enabled true
162160
}
163-
}
161+
}

src/main/java/io/emeraldpay/api/EmeraldConnection.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package io.emeraldpay.api;
22

3-
import io.grpc.Channel;
4-
import io.grpc.ManagedChannelBuilder;
5-
import io.grpc.netty.NettyChannelBuilder;
3+
import io.grpc.*;
4+
import io.grpc.netty.*;
65

7-
import java.io.IOException;
8-
import java.net.InetAddress;
9-
import java.util.function.Function;
6+
import java.net.*;
7+
import java.util.function.*;
108

119
/**
1210
* A connection configuration to access Emerald APIs
@@ -43,6 +41,7 @@ public static class Builder {
4341
private String host;
4442
private Integer port;
4543
private boolean usePlaintext = false;
44+
private boolean useLoadBalancing = true;
4645

4746
/**
4847
* Default Netty config allows messages up to 4Mb, but in practice Ethereum RPC responses may be larger. Here it allows up to 32Mb by default.
@@ -95,6 +94,11 @@ public Builder usePlaintext() {
9594
return this;
9695
}
9796

97+
public Builder disableLoadBalancing() {
98+
this.useLoadBalancing = false;
99+
return this;
100+
}
101+
98102
/**
99103
* St max inbound message size. Default is 32mb.
100104
*
@@ -153,6 +157,10 @@ public EmeraldConnection build() {
153157
channelBuilder = nettyChannelBuilder;
154158
}
155159

160+
if (useLoadBalancing) {
161+
channelBuilder.defaultLoadBalancingPolicy("round_robin");
162+
}
163+
156164
return new EmeraldConnection(channelBuilder.build());
157165
}
158166

0 commit comments

Comments
 (0)