Skip to content

Commit 3d85e3b

Browse files
authored
Merge pull request #161 from bhaan/reconnect-interval
Configurable reconnect interval
2 parents 1ee85d1 + 09f2438 commit 3d85e3b

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

config/configuration.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const (
1313
TransportDataDictionary string = "TransportDataDictionary"
1414
AppDataDictionary string = "AppDataDictionary"
1515
ResetOnLogon string = "ResetOnLogon"
16+
ReconnectInterval string = "ReconnectInterval"
1617
HeartBtInt string = "HeartBtInt"
1718
FileLogPath string = "FileLogPath"
1819
FileStorePath string = "FileStorePath"

config/doc.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ If set to N, fields that are out of order (i.e. body fields in the header, or he
107107
108108
Defaults to Y.
109109
110+
ReconnectInterval
111+
112+
Time between reconnection attempts in seconds. Only used for initiators. Value must be positive integer.
113+
114+
Defaults to 30
115+
110116
HeartBtInt
111117
112118
Heartbeat interval in seconds. Only used for initiators. Value must be positive integer.

connection.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import (
88
)
99

1010
//Picks up session from net.Conn Initiator
11-
func handleInitiatorConnection(address string, log Log, sessID SessionID, quit chan bool) {
12-
reconnectInterval := 30 * time.Second
11+
func handleInitiatorConnection(address string, log Log, sessID SessionID, quit chan bool, reconnectInterval time.Duration) {
1312
session := activate(sessID)
1413
if session == nil {
1514
log.OnEventf("Session not found for SessionID: %v", sessID)

initiator.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package quickfix
22

33
import (
44
"fmt"
5+
"time"
6+
57
"github.com/quickfixgo/quickfix/config"
68
)
79

@@ -32,8 +34,17 @@ func (i *Initiator) Start() error {
3234
return fmt.Errorf("error on SocketConnectPort: %v", err)
3335
}
3436

37+
var reconnectInterval int = 30 // Default configuration (in seconds)
38+
if s.HasSetting(config.ReconnectInterval) {
39+
if reconnectInterval, err = s.IntSetting(config.ReconnectInterval); err != nil {
40+
return fmt.Errorf("error on ReconnectInterval: %v", err)
41+
} else if reconnectInterval <= 0 {
42+
return fmt.Errorf("ReconnectInterval must be greater than zero")
43+
}
44+
}
45+
3546
address := fmt.Sprintf("%v:%v", socketConnectHost, socketConnectPort)
36-
go handleInitiatorConnection(address, i.globalLog, sessionID, i.quitChan)
47+
go handleInitiatorConnection(address, i.globalLog, sessionID, i.quitChan, time.Duration(reconnectInterval)*time.Second)
3748
}
3849

3950
return nil

0 commit comments

Comments
 (0)