Skip to content

Commit

Permalink
Add proxy config
Browse files Browse the repository at this point in the history
  • Loading branch information
bakaoh committed Mar 27, 2019
1 parent cbccf09 commit 40d7ebd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
Expand Down
11 changes: 10 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 40d7ebd

Please sign in to comment.