...

Text file src/github.com/twmb/franz-go/examples/requesting/README.md

Documentation: github.com/twmb/franz-go/examples/requesting

     1# Message requests
     2
     3With franz-go you can directly construct message requests and send them to your Kafka cluster. There are three options
     4how you can issue requests:
     5
     6- Using the broker's `Request` method
     7- Using the client's `Request` method
     8- Using the message's `RequestWith` method
     9
    10## Broker Requests
    11
    12**Interface:**
    13
    14```go
    15func (b *Broker) Request(ctx context.Context, req kmsg.Request) (kmsg.Response, error)
    16```
    17
    18Reference:  https://pkg.go.dev/github.com/twmb/franz-go/pkg/kgo#Broker.Request
    19
    20Use this method only if you need to send requests to a specific broker. The actual response type has to be asserted.
    21Requests sent using this method are not retried.
    22
    23
    24## Client Requests
    25
    26```go
    27func (cl *Client) Request(ctx context.Context, req kmsg.Request) (kmsg.Response, error)
    28```
    29
    30Reference: https://pkg.go.dev/github.com/twmb/franz-go/pkg/kgo#Client.Request
    31
    32The client provides a lot functionality making sure that your message request will be sent in the most efficient manner
    33to the right set of brokers. Additionally it will retry your requests if needed. The actual response type has to be
    34asserted.
    35
    36## Message Requests
    37
    38```go
    39// Example for ListOffsetsRequest
    40func (v *ListOffsetsRequest) RequestWith(ctx context.Context, r Requestor) (*ListOffsetsResponse, error)
    41```
    42
    43Reference: https://pkg.go.dev/github.com/twmb/franz-go/pkg/kmsg
    44
    45Each request message in the `kmsg` package has it's own `RequestWith` method which accepts a context and an interface
    46which `Client` already fulfills. This method uses the client's `Request` method with the advantage that you don't
    47need to assert the actual response type.
    48
    49Most commonly you want to use this method to send requests to Kafka.

View as plain text