Skip to content

Commit

Permalink
More documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Nov 2, 2023
1 parent a77a432 commit 703eb25
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/main/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ A service is addressed with a `{@link io.vertx.serviceresolver.ServiceAddress}`
{@link examples.ServiceResolverExamples#usingHttpClient}
----

=== Client side load balancing

The default load balancing behavior is _round-robin_, you can change the load balancer to use:

[source,java]
----
{@link examples.ServiceResolverExamples#configuringHttpClientWithLoadBalancing}
----

== Kubernetes resolver

The Kubernetes resolver locates services within a Kubernetes cluster.
Expand All @@ -43,7 +52,9 @@ You can override these settings

== SRV resolver

== Client side load balancing

todo
The SRV resolver uses DNS SRV records to resolve and locate services.

[source,java]
----
{@link examples.ServiceResolverExamples#configuringSRVResolver}
----
23 changes: 23 additions & 0 deletions src/main/java/examples/ServiceResolverExamples.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
import io.vertx.core.Vertx;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.*;
import io.vertx.core.loadbalancing.LoadBalancer;
import io.vertx.core.net.AddressResolver;
import io.vertx.docgen.Source;
import io.vertx.serviceresolver.ServiceAddress;
import io.vertx.serviceresolver.ServiceResolver;
import io.vertx.serviceresolver.kube.KubeResolver;
import io.vertx.serviceresolver.kube.KubeResolverOptions;
import io.vertx.serviceresolver.srv.SrvResolver;
import io.vertx.serviceresolver.srv.SrvResolverOptions;

@Source
public class ServiceResolverExamples {
Expand Down Expand Up @@ -50,6 +53,14 @@ public void usingHttpClient(HttpClient client) {
}));
}

public void configuringHttpClientWithLoadBalancing(Vertx vertx, AddressResolver resolver) {

HttpClient client = vertx.httpClientBuilder()
.withAddressResolver(resolver)
.withLoadBalancer(LoadBalancer.LEAST_REQUESTS)
.build();
}

public void usingKubernetesResolver(Vertx vertx) {

KubeResolverOptions options = new KubeResolverOptions();
Expand All @@ -72,4 +83,16 @@ public void configuringKubernetesResolver(String host, int port, String namespac
.setWebSocketClientOptions(wsClientOptions);
}

public void configuringSRVResolver(Vertx vertx, String dnsServer, int dnsPort) {

SrvResolverOptions options = new SrvResolverOptions()
.setPort(dnsPort)
.setHost(dnsServer);

ServiceResolver resolver = SrvResolver.create(options);

HttpClient client = vertx.httpClientBuilder()
.withAddressResolver(resolver)
.build();
}
}

0 comments on commit 703eb25

Please sign in to comment.