diff --git a/config/configuration.go b/config/configuration.go index 810c863f2..fde3c2e73 100644 --- a/config/configuration.go +++ b/config/configuration.go @@ -13,6 +13,7 @@ const ( TransportDataDictionary string = "TransportDataDictionary" AppDataDictionary string = "AppDataDictionary" ResetOnLogon string = "ResetOnLogon" + ReconnectInterval string = "ReconnectInterval" HeartBtInt string = "HeartBtInt" FileLogPath string = "FileLogPath" FileStorePath string = "FileStorePath" diff --git a/config/doc.go b/config/doc.go index c33d74384..45c800c9a 100644 --- a/config/doc.go +++ b/config/doc.go @@ -107,6 +107,12 @@ If set to N, fields that are out of order (i.e. body fields in the header, or he Defaults to Y. +ReconnectInterval + +Time between reconnection attempts in seconds. Only used for initiators. Value must be positive integer. + +Defaults to 30 + HeartBtInt Heartbeat interval in seconds. Only used for initiators. Value must be positive integer. diff --git a/connection.go b/connection.go index 8e667f2fc..7a5a939cf 100644 --- a/connection.go +++ b/connection.go @@ -8,8 +8,7 @@ import ( ) //Picks up session from net.Conn Initiator -func handleInitiatorConnection(address string, log Log, sessID SessionID, quit chan bool) { - reconnectInterval := 30 * time.Second +func handleInitiatorConnection(address string, log Log, sessID SessionID, quit chan bool, reconnectInterval time.Duration) { session := activate(sessID) if session == nil { log.OnEventf("Session not found for SessionID: %v", sessID) diff --git a/initiator.go b/initiator.go index b9b55ce95..f15f4063e 100644 --- a/initiator.go +++ b/initiator.go @@ -2,6 +2,8 @@ package quickfix import ( "fmt" + "time" + "github.com/quickfixgo/quickfix/config" ) @@ -32,8 +34,17 @@ func (i *Initiator) Start() error { return fmt.Errorf("error on SocketConnectPort: %v", err) } + var reconnectInterval int = 30 // Default configuration (in seconds) + if s.HasSetting(config.ReconnectInterval) { + if reconnectInterval, err = s.IntSetting(config.ReconnectInterval); err != nil { + return fmt.Errorf("error on ReconnectInterval: %v", err) + } else if reconnectInterval <= 0 { + return fmt.Errorf("ReconnectInterval must be greater than zero") + } + } + address := fmt.Sprintf("%v:%v", socketConnectHost, socketConnectPort) - go handleInitiatorConnection(address, i.globalLog, sessionID, i.quitChan) + go handleInitiatorConnection(address, i.globalLog, sessionID, i.quitChan, time.Duration(reconnectInterval)*time.Second) } return nil