Skip to content
This repository has been archived by the owner on Dec 14, 2020. It is now read-only.

Commit

Permalink
Add ConnContainerID to allow explicitly configuring the container-id.
Browse files Browse the repository at this point in the history
Default behavior remains randomly generating the container-id.

Resolves #116
  • Loading branch information
vcabbage committed Aug 1, 2018
1 parent 4b9cda8 commit 0ae7451
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ func ConnProperty(key, value string) ConnOption {
}
}

// ConnContainerID sets the container-id to use when opening the connection.
//
// A container ID will be randomly generated if this option is not used.
func ConnContainerID(id string) ConnOption {
return func(c *conn) error {
c.containerID = id
return nil
}
}

// conn is an AMQP connection.
type conn struct {
net net.Conn // underlying connection
Expand All @@ -165,6 +175,7 @@ type conn struct {
hostname string // hostname of remote server (set explicitly or parsed from URL)
idleTimeout time.Duration // maximum period between receiving frames
properties map[symbol]interface{} // additional properties sent upon connection open
containerID string // set explicitly or randomly generated

// peer settings
peerIdleTimeout time.Duration // maximum period between sending frames
Expand Down Expand Up @@ -206,6 +217,7 @@ func newConn(netConn net.Conn, opts ...ConnOption) (*conn, error) {
peerMaxFrameSize: DefaultMaxFrameSize,
channelMax: DefaultMaxSessions - 1, // -1 because channel-max starts at zero
idleTimeout: DefaultIdleTimeout,
containerID: randString(40),
done: make(chan struct{}),
connErr: make(chan error, 2), // buffered to ensure connReader/Writer won't leak
closeMux: make(chan struct{}),
Expand Down Expand Up @@ -763,7 +775,7 @@ func (c *conn) openAMQP() stateFunc {
c.err = c.writeFrame(frame{
type_: frameTypeAMQP,
body: &performOpen{
ContainerID: randString(40),
ContainerID: c.containerID,
Hostname: c.hostname,
MaxFrameSize: c.maxFrameSize,
ChannelMax: c.channelMax,
Expand Down

0 comments on commit 0ae7451

Please sign in to comment.