Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix reconnect issue to gnatsd #221

Merged
merged 3 commits into from Apr 11, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions communication/nats/discovery/address.go
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/mysterium/node/identity"
dto_discovery "github.com/mysterium/node/service_discovery/dto"
nats_lib "github.com/nats-io/go-nats"
"strconv"
)

// NewAddress creates NATS address to known host or cluster of hosts
Expand All @@ -18,7 +19,7 @@ func NewAddress(topic string, addresses ...string) *AddressNATS {

// NewAddressGenerate generates NATS address for current node
func NewAddressGenerate(brokerIP string, myID identity.Identity) *AddressNATS {
address := "nats://" + brokerIP + ":4222"
address := "nats://" + brokerIP + ":" + strconv.Itoa(BrokerPort)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sprintf

return NewAddress(myID.Address, address)
}

Expand Down Expand Up @@ -55,10 +56,13 @@ type AddressNATS struct {
connection nats.Connection
}

// Connect establishes connection
// Connect establishes connection to broker
func (address *AddressNATS) Connect() (err error) {
options := nats_lib.GetDefaultOptions()
options.Servers = address.servers
options.MaxReconnect = BrokerMaxReconnect
options.ReconnectWait = BrokerReconnectWait
options.Timeout = BrokerTimeout

address.connection, err = options.Connect()
return
Expand Down
11 changes: 11 additions & 0 deletions communication/nats/discovery/config.go
@@ -0,0 +1,11 @@
package discovery

import "time"

// Broker Constants
const (
BrokerPort = 4222
BrokerMaxReconnect = -1
BrokerReconnectWait = 4 * time.Second
BrokerTimeout = 5 * time.Second
)