esanchezros / quickfixj-spring-boot-starter

Spring Boot Starter for QuickFIX/J
Apache License 2.0
125 stars 57 forks source link

How to add sessions programmatically #36

Closed alepekhin closed 4 years ago

alepekhin commented 4 years ago

It's not an issue, it is a question. Everything works fine, thank you for publishing this project! The question is how to add sessions dynamically in initiator bypassing configuration file? Suppose we work with a single FIX server where users can be registered/unregistered so we can not place their sessions into config file because we simply don't know their names.

esanchezros commented 4 years ago

Hi alepekhin,

In your service class you can autowire the Initiator and then create, add or remove dynamically a session:

@Autowired
private Initiator clientInitiator;

...

clientInitiator.addDynamicSession(session);
clientInitiator.createDynamicSession(session);
clientInitiator.removeDynamicSession(session);
alepekhin commented 4 years ago

Thank you for a hint. I have tried it, but probably I don't quite understand the topic or may be addDynamicSession() is not fully implemented, so I got the errors like "Responder not set"... After all I have ended with creating separate initiators for every session, like

ThreadedSocketInitiator priceSocketInitiator = new ThreadedSocketInitiator(application, storeFactory, settings, logFactory, new DefaultMessageFactory());
priceSocketInitiator.start();

ThreadedSocketInitiator tradeSocketInitiator = new ThreadedSocketInitiator(application, storeFactory, settings,  logFactory, new DefaultMessageFactory());
tradeSocketInitiator.start();

In this way it works

esanchezros commented 4 years ago

Hi alepekhin,

I found this link that maybe useful https://www.quickfixj.org/usermanual/2.1.0/usage/acceptor_dynamic.html

Registration of a dynamic session provider:

acceptor.setSessionProvider(socketAddress, new DynamicAcceptorSessionProvider( settings, templateSessionID, application, messageStoreFactory, logFactory, messageFactory));

If you could share your code I will have a look and try make it work the way you originally intended.

alepekhin commented 4 years ago

I have also seen this link. It's not very clear, it's about acceptor and does not include username/password as I seen in DynamicAcceptorSessionProvider class. I did not find DynamicInitiatorSessionProvider also. So I will stay with my solution. Anyway clientQuickFixJTemplate works, listeners work too - it's enough for me. Thank you once more for your project. I have added a star to it :)

esanchezros commented 4 years ago

Perhaps the server needs to be configured with the DynamicAcceptorSessionProvider and the clientInitiator is the one requesting the sessions to be added dynamically.