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 Mar 6, 2015
1 parent 20700b5 commit 0480ee3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
11 changes: 10 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 @@ -68,7 +69,15 @@ func (b *Broker) Open(conf *Config) error {
go withRecover(func() {
defer b.lock.Unlock()

b.conn, b.connErr = net.DialTimeout("tcp", b.addr, conf.Net.DialTimeout)
dialer := &net.Dialer{
Timeout: conf.Net.DialTimeout,
}

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 @@ -12,6 +15,11 @@ type Config struct {
DialTimeout time.Duration // How long to wait for the initial connection to succeed before timing out and returning an error (default 30s).
ReadTimeout time.Duration // How long to wait for a response before timing out and returning an error (default 30s).
WriteTimeout time.Duration // How long to wait for a transmit to succeed before timing out and returning an error (default 30s).

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 specified by UseTLS (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 0480ee3

Please sign in to comment.