Skip to content

Commit

Permalink
Add configuration to support broker SSL
Browse files Browse the repository at this point in the history
Possibly implements #154, if my assumptions about the implementation are
correct.
  • Loading branch information
eapache committed Jul 24, 2015
1 parent 2b0d726 commit 67dada4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 7 additions & 1 deletion broker.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sarama

import (
"crypto/tls"
"fmt"
"io"
"net"
Expand Down Expand Up @@ -73,7 +74,12 @@ func (b *Broker) Open(conf *Config) error {
KeepAlive: conf.Net.KeepAlive,
}

b.conn, b.connErr = dialer.Dial("tcp", b.addr)
if conf.Net.TLS.Enable {
b.conn, b.connErr = tls.DialWithDialer(&dialer, "tcp", b.addr, conf.Net.TLS.Config)
} else {
b.conn, b.connErr = dialer.Dial("tcp", b.addr)
}

if b.connErr != nil {
b.conn = nil
atomic.StoreInt32(&b.opened, 0)
Expand Down
10 changes: 9 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package sarama

import "time"
import (
"crypto/tls"
"time"
)

// Config is used to pass multiple configuration options to Sarama's constructors.
type Config struct {
Expand All @@ -16,6 +19,11 @@ type Config struct {
// KeepAlive specifies the keep-alive period for an active network connection.
// If zero, keep-alives are disabled. (default is 0: disabled).
KeepAlive time.Duration

TLS struct {
Enable bool // Whether or not to use TLS when connecting to the broker (defaults to false).
Config *tls.Config // The TLS configuration to use for secure connections if enabled (defaults to nil).
}
}

// Metadata is the namespace for metadata management properties used by the Client, and shared by the Producer/Consumer.
Expand Down

0 comments on commit 67dada4

Please sign in to comment.