kafka-go icon indicating copy to clipboard operation
kafka-go copied to clipboard

Setting Dialer in a new Writer requires doing a Lookup wrapper

Open ake-persson opened this issue 5 months ago • 0 comments

Describe the solution you would like

Defining a new writer should preferably have an option for setting dialer.

w := &kafka.Writer{Dialer: dialer, ...}

Alt. have a helper when defining Dial in Transport.

A clear and concise description of what you want to happen.

Currently you have to define a Dial function that handles Lookup in the Transport. This doesn't seem optimal.

tr := &kafka.Transport{dial: MyFunc(dialer), ...}

This is the current implementation in NewWriter().

dial := func(ctx context.Context, network, addr string) (net.Conn, error) {
		start := time.Now()
		defer func() {
			stats.dials.observe(1)
			stats.dialTime.observe(int64(time.Since(start)))
		}()
		address, err := lookupHost(ctx, addr, resolver)
		if err != nil {
			return nil, err
		}
		return dialer.DialContext(ctx, network, address)
	}

Supporting documentation

Please provides links to relevant Kafka protocol docs and/or KIPs.

ake-persson avatar Sep 03 '24 09:09 ake-persson