Examples: quickfixj-spring-boot-starter-examples
This project is a Spring Boot Starter for QuickFixJ. It simplifies the configuration required to create and start an Initiator or Acceptor, and handles the lifecycle of the Connector.
To use the QuickFixJ Server or QuickFixJ Client you have to add the QuickFixJ Spring Boot Starter dependency in your project.
<dependency>
<groupId>io.allune</groupId>
<artifactId>quickfixj-spring-boot-starter</artifactId>
<version>2.5.0</version>
</dependency>
To enable the actuator endpoints you will also have to add the QuickFixJ Spring Boot Actuator dependency.
<dependency>
<groupId>io.allune</groupId>
<artifactId>quickfixj-spring-boot-actuator</artifactId>
<version>2.5.0</version>
</dependency>
The @EnableQuickFixJServer
will auto configure a QuickFixJ Server:
@EnableQuickFixJServer
@SpringBootApplication
public class AppServer {
public static void main(String[] args) {
SpringApplication.run(AppServer.class, args);
}
}
The configuration can be done in the application.properties / application.yml.
quickfixj:
server:
config: classpath:quickfixj-server.cfg
Additionally you need to add a quickfixj-server.cfg file to configure the FIX sessions. The configuration is resolved using the following approach:
-
By the presence of a
quickfix.SessionSettings
bean namedserverSessionSettings
-
By a configuration file defined by the
quickfixj.server.config
property -
By the presence of the
quickfixj.server.config
system property -
By a
quickfixj-server.cfg
in the working directory or at the root of the classpath
quickfixj.server.config=classpath:quickfixj-server.cfg # location of the quickfixj acceptor
quickfixj.server.auto-startup=true # whether to auto-connect to the remote endpoint at start up
quickfixj.server.phase=0 # phase in which this connection manager should be started and stopped
quickfixj.server.jmx-enabled=true # whether to register the jmx mbeans for the acceptor
quickfixj.server.concurrent.enabled=true # whether to use a simple SocketAcceptor or a ThreadedSocketAcceptor
management.endpoint.quickfixjserver.enabled=true # whether the endpoint is enabled or not
management.endpoints.web.exposure.include=quickfixjserver # whether the endpoint will be exposed
Example usage:
http://localhost:8081/actuator/quickfixjserver
{
"FIX.4.2:EXEC->BANZAI": {
"SenderCompID": "EXEC",
"StartTime": "00:00:00",
"DefaultMarketPrice": "12.30",
"ValidOrderTypes": "1,2,F",
"ConnectionType": "acceptor",
"EndTime": "00:00:00",
"BeginString": "FIX.4.2",
"SocketAcceptPort": "9878",
"TargetCompID": "BANZAI",
"SenderCompID": "EXEC",
"HeartBtInt": "30",
"BeginString": "FIX.4.2",
"TargetCompID": "BANZAI",
"FileStorePath": "target/data/executor",
"UseDataDictionary": "Y"
},
"FIX.4.1:EXEC->BANZAI": {
"SenderCompID": "EXEC",
"StartTime": "00:00:00",
"DefaultMarketPrice": "12.30",
"ValidOrderTypes": "1,2,F",
"ConnectionType": "acceptor",
"EndTime": "00:00:00",
"BeginString": "FIX.4.1",
"SocketAcceptPort": "9877",
"TargetCompID": "BANZAI",
"SenderCompID": "EXEC",
"HeartBtInt": "30",
"BeginString": "FIX.4.1",
"TargetCompID": "BANZAI",
"FileStorePath": "target/data/executor",
"UseDataDictionary": "Y"
}
}
The @EnableQuickFixJClient
will auto configure a QuickFixJ Client:
@EnableQuickFixJClient
@SpringBootApplication
public class AppClient {
public static void main(String[] args) {
SpringApplication.run(AppClient.class, args);
}
}
The configuration can be done in the application.properties / application.yml.
quickfixj:
client:
config: classpath:quickfixj-client.cfg
Additionally you need to add a quickfixj-client.cfg file to configure the FIX sessions. The configuration is resolved using the following approach:
-
By the presence of a
quickfix.SessionSettings
bean namedclientSessionSettings
-
By a configuration file defined by the
quickfixj.client.config
property -
By the presence of the
quickfixj.client.config
system property -
By a
quickfixj-client.cfg
in the working directory or at the root of the classpath
quickfixj.client.config=classpath:quickfixj-client.cfg # location of the quickfixj initiator
quickfixj.client.auto-startup=true # whether to auto-connect to the remote endpoint at start up
quickfixj.client.phase=0 # phase in which this connection manager should be started and stopped
quickfixj.client.jmx-enabled=true # whether to register the jmx mbeans for the initiator
quickfixj.client.concurrent.enabled=true # whether to use a simple SocketInitiator or a ThreadedSocketInitiator
management.endpoint.quickfixjclient.enabled=true # whether the endpoint is enabled or not
management.endpoints.web.exposure.include=quickfixjclient # whether the endpoint will be exposed
Example usage:
http://localhost:8080/actuator/quickfixjclient
{
"FIXT.1.1:BANZAI->EXEC": {
"SenderCompID": "BANZAI",
"StartTime": "00:00:00",
"ConnectionType": "initiator",
"EndTime": "00:00:00",
"BeginString": "FIXT.1.1",
"ReconnectInterval": "5",
"TargetCompID": "EXEC",
"DefaultApplVerID": "FIX.5.0",
"SocketConnectHost": "localhost",
"SenderCompID": "BANZAI",
"HeartBtInt": "30",
"BeginString": "FIXT.1.1",
"TargetCompID": "EXEC",
"FileStorePath": "target/data/banzai",
"SocketConnectPort": "9881"
},
"FIX.4.2:BANZAI->EXEC": {
"SenderCompID": "BANZAI",
"StartTime": "00:00:00",
"ConnectionType": "initiator",
"EndTime": "00:00:00",
"BeginString": "FIX.4.2",
"ReconnectInterval": "5",
"TargetCompID": "EXEC",
"SocketConnectHost": "localhost",
"SenderCompID": "BANZAI",
"HeartBtInt": "30",
"BeginString": "FIX.4.2",
"TargetCompID": "EXEC",
"FileStorePath": "target/data/banzai",
"SocketConnectPort": "9878"
}
}
The QuickFixJ Spring Boot Starter provides a default implementation for the quickfixj.Application
interface which publishes the messages received by the Server (Acceptor) and the Client (Initiator) as `ApplicationEvent`s.
If your application is only processing a subset of message types (i.e. toAdmin
, toApp
, onCreate
, etc.) you will need to register an EventListener
for these, with the appropriate message type as the only parameter for the listener method:
@EventListener
public void listenFromAdmin(FromAdmin fromAdmin) {
...
}
@EventListener
public void listenFromApp(FromApp fromApp) {
...
}
@EventListener
public void listenOnCreate(Create create) {
...
}
@EventListener
public void listenOnLogon(Logon logon) {
...
}
@EventListener
public void listenOnLogout(Logout logout) {
...
}
@EventListener
public void listenToAdmin(ToAdmin toAdmin) {
...
}
@EventListener
public void listenToApp(ToApp toApp) {
...
}
In case the EventListener
method throws an exception, this exception will be propagated up the quickfix.Session#next()
method.
Depending on the value of RejectMessageOnUnhandledException
in the quickfixj configuration file, the message will be redelivered or dismissed.
The QuickFixJTemplate
provides a synchronous client to perform requests, exposing a simple, template method API over the QuickFixJ client.
@EnableQuickFixJServer
provides a serverQuickFixJTemplate
bean and @EnableQuickFixJClient
provides a clientQuickFixJTemplate
bean than can be Autowired
in the application.
@Autowire
private QuickFixJTemplate serverQuickFixJTemplate;
...
SessionID sessionID = serverAcceptor.getSessions().stream()
.filter(sessId ->
sessId.getBeginString().equals(fixVersion) &&
sessId.getTargetCompID().equals(targetId))
.findFirst()
.orElseThrow(RuntimeException::new);
OrderCancelRequest message = new OrderCancelRequest(
new OrigClOrdID("123"),
new ClOrdID("321"),
new Symbol("LNUX"),
new Side(Side.BUY));
serverQuickFixJTemplate.send(message, sessionID);
The QuickFixJ Spring Boot Starter is released under version 2.0 of the Apache License.
This code includes software developed by quickfixengine.org.