From 40d7ebd57605a5081393ef3fae0ade70ef10f2bf Mon Sep 17 00:00:00 2001 From: bakaoh Date: Wed, 27 Mar 2019 13:51:16 +0700 Subject: [PATCH] Add proxy config --- broker.go | 4 +++- config.go | 11 ++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/broker.go b/broker.go index 42e1f45290..f043ecba9c 100644 --- a/broker.go +++ b/broker.go @@ -13,7 +13,7 @@ import ( "sync/atomic" "time" - "github.com/rcrowley/go-metrics" + metrics "github.com/rcrowley/go-metrics" ) // Broker represents a single Kafka broker connection. All operations on this object are entirely concurrency-safe. @@ -155,6 +155,8 @@ func (b *Broker) Open(conf *Config) error { if conf.Net.TLS.Enable { b.conn, b.connErr = tls.DialWithDialer(&dialer, "tcp", b.addr, conf.Net.TLS.Config) + } else if conf.Net.Proxy.Enable { + b.conn, b.connErr = conf.Net.Proxy.Dialer.Dial("tcp", b.addr) } else { b.conn, b.connErr = dialer.Dial("tcp", b.addr) } diff --git a/config.go b/config.go index 6fa8bb940a..4931fb540d 100644 --- a/config.go +++ b/config.go @@ -9,7 +9,8 @@ import ( "regexp" "time" - "github.com/rcrowley/go-metrics" + metrics "github.com/rcrowley/go-metrics" + "golang.org/x/net/proxy" ) const defaultClientID = "sarama" @@ -85,6 +86,14 @@ type Config struct { // network being dialed. // If nil, a local address is automatically chosen. LocalAddr net.Addr + + Proxy struct { + // Whether or not to use proxy when connecting to the broker + // (defaults to false). + Enable bool + // The proxy dialer to use enabled (defaults to nil). + Dialer proxy.Dialer + } } // Metadata is the namespace for metadata management properties used by the