Skip to content

Commit f817efe

Browse files
committed
Document address resolver hook
Fixes #124
1 parent 4c7cd75 commit f817efe

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

src/docs/asciidoc/api.adoc

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ will pick a new URI randomly in case of disconnection.
7272
===== Understanding Connection Logic
7373

7474
Creating the environment to connect to a cluster node works usually seamlessly.
75-
Creating publishers and consumers can cause problems as the client uses hints from the cluster to locate the nodes where stream leaders and replicas are located to connect to the appropriate nodes.
75+
Creating publishers and consumers can cause problems as the client uses hints from the cluster to find the nodes where stream leaders and replicas are located to connect to the appropriate nodes.
7676

7777
These connection hints can be accurate or less appropriate depending on the infrastructure.
7878
If you hit some connection problems at some point – like hostnames impossible to resolve for client applications - this https://blog.rabbitmq.com/posts/2021/07/connecting-to-streams/[blog post] should help you understand what is going on and fix the issues.
@@ -204,6 +204,10 @@ a new connection is open. The value must be between 1 and 255.
204204
Used as a prefix for connection names.
205205
|`rabbitmq-stream`
206206

207+
|`addressResolver`
208+
|Contract to change resolved node address to connect to.
209+
|Pass-through (no-op)
210+
207211
|`tls`
208212
|Configuration helper for TLS.
209213
|TLS is enabled if a `rabbitmq-stream+tls` URI is provided.
@@ -225,6 +229,24 @@ and does not use a client private key. **Only for development**.
225229
|Disabled by default.
226230
|===
227231

232+
===== When a Load Balancer is in Use
233+
234+
A load balancer can misguide the client when it tries to connect to nodes that host stream leaders and replicas.
235+
The https://blog.rabbitmq.com/posts/2021/07/connecting-to-streams/["Connecting to Streams"] blog post covers why client applications must connect to the appropriate nodes in a cluster and how a https://blog.rabbitmq.com/posts/2021/07/connecting-to-streams/#with-a-load-balancer[load balancer can make things complicated] for them.
236+
237+
The `EnvironmentBuilder#addressResolver(AddressResolver)` method allows intercepting the node resolution after metadata hints and before connection.
238+
Applications can use this hook to ignore metadata hints and always use the load balancer, as illustrated in the following snippet:
239+
240+
.Using a custom address resolver to always use a load balancer
241+
[source,java,indent=0]
242+
--------
243+
include::{test-examples}/EnvironmentUsage.java[tag=address-resolver]
244+
--------
245+
<1> Set the load balancer address
246+
<2> Use load balancer address for initial connection
247+
<3> Ignore metadata hints, always use load balancer
248+
249+
The blog post covers the https://blog.rabbitmq.com/posts/2021/07/connecting-to-streams/#client-workaround-with-a-load-balancer[underlying details of this workaround].
228250

229251
===== Managing Streams
230252

src/docs/asciidoc/performance-tool.adoc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,20 @@ java -jar stream-perf-test.jar --producer-names %s-%d
477477

478478
The run will start one producer and will use the `stream-1` producer reference (default stream is `stream` and the number of the producer is 1.)
479479

480+
===== Load Balancer in Front of the Cluster
481+
482+
A load balancer can misguide the performance tool when it tries to connect to nodes that host stream leaders and replicas.
483+
The https://blog.rabbitmq.com/posts/2021/07/connecting-to-streams/["Connecting to Streams"] blog post covers why client applications must connect to the appropriate nodes in a cluster.
484+
485+
Use the `--load-balancer` flag to make sure the performance tool always goes through the load balancer that sits in front of your cluster:
486+
487+
----
488+
java -jar stream-perf-test.jar --uris rabbitmq-stream://my-load-balancer:5552 \
489+
--load-balancer
490+
----
491+
492+
The same blog post covers why a https://blog.rabbitmq.com/posts/2021/07/connecting-to-streams/#with-a-load-balancer[load balancer can make things more complicated] for client applications like the performance tool and how https://blog.rabbitmq.com/posts/2021/07/connecting-to-streams/#client-workaround-with-a-load-balancer[they can mitigate these issues].
493+
480494
===== Monitoring
481495

482496
The tool can expose some runtime information on HTTP.

src/test/java/com/rabbitmq/stream/docs/EnvironmentUsage.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
package com.rabbitmq.stream.docs;
1616

17+
import com.rabbitmq.stream.Address;
1718
import com.rabbitmq.stream.ByteCapacity;
1819
import com.rabbitmq.stream.Environment;
1920

@@ -86,6 +87,17 @@ void environmentCreationWithTlsTrustEverything() throws Exception {
8687
// end::environment-creation-with-tls-trust-everything[]
8788
}
8889

90+
void addressResolver() throws Exception {
91+
// tag::address-resolver[]
92+
Address entryPoint = new Address("my-load-balancer", 5552); // <1>
93+
Environment environment = Environment.builder()
94+
.host(entryPoint.host()) // <2>
95+
.port(entryPoint.port()) // <2>
96+
.addressResolver(address -> entryPoint) // <3>
97+
.build();
98+
// end::address-resolver[]
99+
}
100+
89101
void createStream() {
90102
Environment environment = Environment.builder().build();
91103
// tag::stream-creation[]

0 commit comments

Comments
 (0)