DynamicSessions are incompatible with any MessageStore except the in memory store
mattrasband opened this issue · comments
Because dynamic sessions don't have a setting associated with them most message stores reject them:
File Message Store:
Lines 48 to 51 in 94d7217
SQL Store:
Lines 54 to 57 in 94d7217
Mongo Store:
Lines 45 to 48 in 94d7217
It seems like in the case the session settings aren't found we should default back to the global settings if possible for dynamic session cases.
If this seems sensible I could work on adding it.
As a workaround, is it safe to compose one of these and in the Create
implementation dynamically generate the session and save it to the settings?
It certainly feels hacky, but something like:
type dynamicMessageFactory struct {
store quickfix.MessageStoreFactory
settings *quickfix.Settings
mu sync.Mutex
}
func newDynamicMessageFactory(settings *quickfix.Settings, composed quickfix.MessageStoreFactory) quickfix.MessageStoreFactory {
return &dynamicMessageFactory{
store: composed,
settings: settings,
}
}
func (dfs *dynamicMessageFactory) Create(sessionID quickfix.SessionID) (msgStore quickfix.MessageStore, err error) {
dfs.mu.Lock()
if _, ok := dfs.settings.SessionSettings()[sessionID]; !ok {
session := quickfix.NewSessionSettings()
session.Set(config.BeginString, sessionID.BeginString)
session.Set(config.TargetCompID, sessionID.TargetCompID)
session.Set(config.TargetSubID, sessionID.TargetSubID)
session.Set(config.TargetLocationID, sessionID.TargetLocationID)
session.Set(config.SenderCompID, sessionID.SenderCompID)
session.Set(config.SenderSubID, sessionID.SenderSubID)
session.Set(config.SenderLocationID, sessionID.SenderLocationID)
session.Set(config.SessionQualifier, sessionID.Qualifier)
if sessionID.TargetCompID == "MD" {
session.Set(config.PersistMessages, "N")
}
dfs.settings.AddSession(session)
}
dfs.mu.Unlock()
return dfs.store.Create(sessionID)
}