When I try to call the constructor of SessionSettings with the URL of the config file, it loads only the last session exists in the file.
I have tried print what my code is reading from the config file but I got this:
[DEFAULT]
StartTime=00:00:00
EndTime=23:59:59
ReconnectInterval=5
TargetCompID=Server
SenderCompID=Client
DataDictionary=C:\config\FIX42.xml
HeartBtInt=30
FileStorePath=C:\logsBadisInitiatorStore
UseDataDictionary=Y
FileLogPath=C:\logsBadisInitiator
[SESSION]
StartTime=00:00:00
ConnectionType=acceptor
EndTime=23:59:59
BeginString=FIX.4.2
SocketAcceptPort=9878
TargetCompID=server1
SessionName=badisAcc289
SenderCompID=client1
SocketAcceptAddress=localhost
UseDataDictionary=N
But my config file contains more than that:
[default]
FileStorePath=data
SenderCompID=Client
TargetCompID=Server
FileLogPath=C:\logsBadisInitiator
StartTime=00:00:00
EndTime=23:59:59
HeartBtInt=30
ReconnectInterval=5
UseDataDictionary=Y
DataDictionary=C:\config\FIX42.xml
FileStorePath=C:\logsBadisInitiatorStore
[session]
SessionName=badisAcc2
BeginString=FIX.4.2
SenderCompID=client1
TargetCompID=server1
ConnectionType=acceptor
SocketAcceptPort=9878
SocketAcceptAddress=localhost
StartTime=00:00:00
EndTime=23:59:59
UseDataDictionary=N
[session]
SessionName=test211
BeginString=FIX.4.2
SenderCompID=client1
TargetCompID=server1
ConnectionType=initiator
SocketConnectPort=9878
SocketConnectHost=localhost
StartTime=00:00:00
EndTime=23:59:59
UseDataDictionary=N
[session]
SessionName=badisAcc3
BeginString=FIX.4.2
SenderCompID=client1
TargetCompID=server1
ConnectionType=acceptor
SocketAcceptPort=9878
SocketAcceptAddress=localhost
StartTime=00:00:00
EndTime=23:59:59
UseDataDictionary=N
[session]
SessionName=badisAcc4
BeginString=FIX.4.2
SenderCompID=client1
TargetCompID=server1
ConnectionType=acceptor
SocketAcceptPort=9878
SocketAcceptAddress=localhost
StartTime=00:00:00
EndTime=23:59:59
UseDataDictionary=N
[session]
SessionName=badisAcc289
BeginString=FIX.4.2
SenderCompID=client1
TargetCompID=server1
ConnectionType=acceptor
SocketAcceptPort=9878
SocketAcceptAddress=localhost
StartTime=00:00:00
EndTime=23:59:59
UseDataDictionary=N
This is the code that I wrote to load the sessionSettings:
String URLConfigFile="c:/config/initiatorSettings.txt";
sessionSettings = new SessionSettings(URLConfigFile);
System.out.println("sessionSettings tostring "+sessionSettings.toString());
How do I resolve this?
Root cause One session's config is clobbering the other, because both sessions have the same SessionID.
Both of your sessions have the same SessionID, which is constructed from BeginString/SenderCompID/TargetCompID (and sometimes other fields).
The SessionSetting is actually a hash of individual dictionaries for each session, keyed by SessionID. Since your sessions have the same SessionID, they're clobbering each other.
Your config also has a logical problem
If you want these two sessions to talk to each other, then the Sender/Target values should be opposite, e.g.
[session]
SessionName=badisAcc2
BeginString=FIX.4.2
SenderCompID=server1
TargetCompID=client1
ConnectionType=acceptor
...
[session]
SessionName=test211
BeginString=FIX.4.2
SenderCompID=client1
TargetCompID=server1
ConnectionType=initiator
...