|
From: Colin D. <co...@ma...> - 2021-04-20 15:33:12
|
Here's the code. Note that this dates back to 1.6.3. It still runs fine
on the current release of QFJ, but not sure if everything we did is
still required.
In 1.6.3, dynamically adding sessions worked, but dynamically removing
them did not. We had to make some changes to allow that to happen. Other
than that, it was pretty straightforward.
Here is our code for doing this:
quickfix.SessionSettings fixSessionSettings =
brokerService.generateSessionSettings(sessions);
fixSessionSettings.setString(quickfix.Acceptor.SETTING_SOCKET_ACCEPT_ADDRESS,
String.valueOf(dareAcceptorHostname));
fixSessionSettings.setString(quickfix.Acceptor.SETTING_SOCKET_ACCEPT_PORT,
String.valueOf(dareAcceptorPort));
FixSettingsProvider fixSettingsProvider =
fixSettingsProviderFactory.create();
socketAcceptor = new DynamicSessionThreadedSocketAcceptor(this,
fixSettingsProvider.getMessageStoreFactory(fixSessionSettings),
fixSessionSettings,
fixSettingsProvider.getLogFactory(fixSessionSettings),
fixSettingsProvider.getMessageFactory(),
sessionService);
provider = new DynamicAcceptorSessionProvider(this,
brokerService,
fixSessionProvider,
sessionNameProvider,
fixSettingsProvider,
clusterData);
socketAcceptor.setSessionProvider(new
InetSocketAddress(dareAcceptorHostname,
dareAcceptorPort),
provider);
Some of this stuff you'll have to figure out (or you can ask me
questions about it), but, it should give you the general picture.
You generate your SessionSettings object which has the settings for your
session(s). We created a custom extension of ThreadedSocketAcceptor
called DynamicAcceptorSessionProvider, but, the only customizations we
had to make were for dynamically removing sessions, not adding them.
To add a new session during runtime:
// session doesn't exist yet, check to see if
there's a session that matches in the DB
if(fixSession.isEnabled()) {
quickfix.Session session =
Session.lookupSession(newSessionId);
if(session == null) {
// session exists in the DB, generate
FIX settings for it
quickfix.SessionSettings newSettings =
brokerService.generateSessionSettings(Lists.newArrayList(fixSession));
quickfix.SessionSettings
existingSettings = socketAcceptor.getSettings();
FixSettingsProvider fixSettingsProvider
= fixSettingsProviderFactory.create();
try {
Properties newSessionProperties =
newSettings.getSessionProperties(newSessionId);
for(Map.Entry<Object,Object> entry : newSessionProperties.entrySet()) {
String key =
String.valueOf(entry.getKey());
String value =
String.valueOf(entry.getValue());
existingSettings.setString(newSessionId,
key,
value);
}
SessionFactory factory = new
DefaultSessionFactory(this,
fixSettingsProvider.getMessageStoreFactory(existingSettings),
fixSettingsProvider.getLogFactory(existingSettings),
fixSettingsProvider.getMessageFactory());
// this will force the session to
exist, which puts it back in the mix
session = factory.create(newSessionId,
newSettings);
socketAcceptor.addDynamicSession(session);
} catch (ConfigError e) {
SLF4JLoggerProxy.warn(this,
e);
}
}
}
The key here is to generate a new set of SessionSettings (using the
default session settings to start) and then calling addDynamicSession.
On 4/17/21 10:36 AM, Ajit Gautam wrote:
> QuickFIX/J Documentation: http://www.quickfixj.org/documentation/
> QuickFIX/J Support: http://www.quickfixj.org/support/
>
>
>
> Thanks Colin for the prompt response. It will be helpful for me if you
> can give an insight of the changes required.
>
> Regards
> Ajit
>
> On Fri, Apr 16, 2021, 22:55 Colin DuPlantis <co...@ma...
> <mailto:co...@ma...>> wrote:
>
> QuickFIX/J Documentation: http://www.quickfixj.org/documentation/
> QuickFIX/J <http://www.quickfixj.org/documentation/QuickFIX/J>
> Support: http://www.quickfixj.org/support/
> <http://www.quickfixj.org/support/>
>
>
> Yes, this is possible.
>
> Since the issue is adding session dynamically, the config settings
> won't reflect the new sessions. You have to add one default
> session or the acceptor won't start.
>
> I can share the code in a little bit. I have to step away right now.
>
> On 4/16/21 10:21 AM, Ajit Gautam wrote:
>> QuickFIX/J Documentation:http://www.quickfixj.org/documentation/ <http://www.quickfixj.org/documentation/>
>> QuickFIX/J Support:http://www.quickfixj.org/support/ <http://www.quickfixj.org/support/>
>>
>>
>>
>> Hi,
>>
>> Can we add the session dynamically in Quickfix acceptor??
>>
>> Can anybody share the setting file as well.
>>
>> Regards
>> Ajit G
>>
>>
>> _______________________________________________
>> Quickfixj-users mailing list
>> Qui...@li... <mailto:Qui...@li...>
>> https://lists.sourceforge.net/lists/listinfo/quickfixj-users <https://lists.sourceforge.net/lists/listinfo/quickfixj-users>
>
> --
> Colin DuPlantis
> Chief Architect, Marketcetera
> Download, Run, Trade
> 888.868.4884
> https://www.marketcetera.com <https://www.marketcetera.com>
>
> _______________________________________________
> Quickfixj-users mailing list
> Qui...@li...
> <mailto:Qui...@li...>
> https://lists.sourceforge.net/lists/listinfo/quickfixj-users
> <https://lists.sourceforge.net/lists/listinfo/quickfixj-users>
>
>
>
> _______________________________________________
> Quickfixj-users mailing list
> Qui...@li...
> https://lists.sourceforge.net/lists/listinfo/quickfixj-users
--
Colin DuPlantis
Chief Architect, Marketcetera
Download, Run, Trade
888.868.4884
https://www.marketcetera.com
|