MCPcopy
hub / github.com/segmentio/kafka-go / ExampleNewReader_rackAffinity

Function ExampleNewReader_rackAffinity

example_groupbalancer_test.go:17–31  ·  view source on GitHub ↗

ExampleNewReader_rackAffinity shows how the RackAffinityGroupBalancer can be used to pair up consumers with brokers in the same AWS availability zone. This code assumes that each brokers' rack is configured to be the name of the AZ in which it is running.

()

Source from the content-addressed store, hash-verified

15// This code assumes that each brokers' rack is configured to be the name of the
16// AZ in which it is running.
17func ExampleNewReader_rackAffinity() {
18 r := NewReader(ReaderConfig{
19 Brokers: []string{"kafka:9092"},
20 GroupID: "my-group",
21 Topic: "my-topic",
22 GroupBalancers: []GroupBalancer{
23 RackAffinityGroupBalancer{Rack: findRack()},
24 RangeGroupBalancer{},
25 },
26 })
27
28 r.ReadMessage(context.Background())
29
30 r.Close()
31}
32
33// findRack is the basic rack resolver strategy for use in AWS. It supports
34// * ECS with the task metadata endpoint enabled (returns the container

Callers

nothing calls this directly

Calls 4

ReadMessageMethod · 0.95
CloseMethod · 0.95
NewReaderFunction · 0.85
findRackFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…