Skip to content

Spring Boot

The starter declares the whole engine in application.properties. Your Java is reduced to the one thing Spring cannot write for you: the FixApplication beans that handle your business messages.

<dependency>
    <groupId>org.lolaf.staffix</groupId>
    <artifactId>staffix-spring-boot-starter</artifactId>
    <version>${staffix.version}</version>
</dependency>

Working example: spring-boot-starter-example.


The shape of the configuration

Every pluggable part is a property namespace, and instances are keyed by the same instance ids used in Java; see Configuring a session. The pattern is staffix.<part>.instances.<INSTANCE_ID>.<setting>.

staffix.enabled=true

# the executor for sessions that have no connection, a bean of yours rather than the engine's own thread;
# it must be single threaded, see docs/threading-model.md
staffix.engine.disconnected-sessions-executor-bean=offlineSessionsExecutor

# stores and loggers, one instance each for the acceptor and the initiator
staffix.messages-stores-memory.instances.ACCEPTOR.max-entries-in-memory=1024
staffix.messages-stores-memory.instances.INITIATOR.max-entries-in-memory=1024
staffix.messages-loggers-slf4j.instances.ACCEPTOR.message-fields-delimiter=|
staffix.messages-loggers-slf4j.instances.INITIATOR.message-fields-delimiter=|

Sessions

Sessions live in a settings store instance and are declared as an indexed list:

staffix.sessions-settings-stores-memory.instances.SHARED.sessions[0].type=acceptor
staffix.sessions-settings-stores-memory.instances.SHARED.sessions[0].fix-session-id.name=acceptor-session-1
staffix.sessions-settings-stores-memory.instances.SHARED.sessions[0].fix-session-id.fix-version=VERSION_44
staffix.sessions-settings-stores-memory.instances.SHARED.sessions[0].fix-session-id.sender-comp-id=ACCEPTOR
staffix.sessions-settings-stores-memory.instances.SHARED.sessions[0].fix-session-id.target-comp-id=INITIATOR_1
staffix.sessions-settings-stores-memory.instances.SHARED.sessions[0].fix-message-store-instance-id=ACCEPTOR
staffix.sessions-settings-stores-memory.instances.SHARED.sessions[0].fix-message-logger-instance-id=ACCEPTOR
staffix.sessions-settings-stores-memory.instances.SHARED.sessions[0].fix-application-instance-id=acceptorApp
staffix.sessions-settings-stores-memory.instances.SHARED.sessions[0].reset-seq-num-on-logon=true

Every setting from Configuring a session is available here in kebab-case, including nested groups:

…sessions[1].heartbeat.initiator-interval=2s

fix-application-instance-id is a Spring bean name. That is the join between the two worlds:

@Bean("acceptorApp")
public FixApplication acceptorApp() {
    return new MyAcceptorApplication();
}

The session speaks that bean's dictionary, getDictionaryId(), so its fix-version must be the dictionary's.


Acceptors and initiators

staffix.acceptors.primary.instance-id=ACCEPTOR
staffix.acceptors.primary.bind-address=localhost:17001
staffix.acceptors.primary.target-sessions-settings-store-instance-ids[0]=SHARED
staffix.acceptors.primary.io-workers.thread-groups[0].name=default
staffix.acceptors.primary.io-workers.thread-groups[0].io-thread-count=1
staffix.acceptors.primary.io-workers.thread-groups[0].select-strategy=WAKEUP
staffix.acceptors.primary.message-executor.executors-threads-count=1
staffix.acceptors.primary.message-executor.idle-strategy=WAIT_NOTIFY

staffix.initiators.primary.instance-id=INITIATOR_1
staffix.initiators.primary.main-target.fix-session-id.name=initiator-session-1
staffix.initiators.primary.main-target.fix-session-id.fix-version=VERSION_44
staffix.initiators.primary.main-target.fix-session-id.sender-comp-id=INITIATOR_1
staffix.initiators.primary.main-target.fix-session-id.target-comp-id=ACCEPTOR
staffix.initiators.primary.main-target.connect-addresses[0]=localhost:17001
staffix.initiators.primary.connection-retry=PT1S
staffix.initiators.primary.backup-targets[0].fix-session-id.name=initiator-session-1-dr
staffix.initiators.primary.backup-targets[0].fix-session-id.fix-version=VERSION_44
staffix.initiators.primary.backup-targets[0].fix-session-id.sender-comp-id=INITIATOR_1
staffix.initiators.primary.backup-targets[0].fix-session-id.target-comp-id=ACCEPTOR_DR
staffix.initiators.primary.backup-targets[0].connect-addresses[0]=dr-host:17001

main-target is the session the initiator runs when it starts. backup-targets are sessions it can be switched to through the Admin API; it never switches on its own. The main target needs session settings in a sessions settings store; a backup runs on them under its own session id and must have none of its own. The same session on another host is one more entry in its connect-addresses.

select-strategy and idle-strategy are the latency knobs from Tuning for latency, as enum names rather than constructed objects: WAKEUP for the blocking selector, and the idle strategies by name. This is the one place where the properties surface is narrower than the Java one: a custom SelectStrategy or ThreadFactory needs a bean or Java configuration.

scheduler-bean names a bean to use as the scheduler, so the engine's timers share your application's executor rather than creating their own.


Monitoring and admin

staffix.admin-api-jmx.domain=com.example.trading

staffix.admin-api-http.port=8686
staffix.admin-api-http.ssl-bundle=admin
staffix.admin-api-http.announce-url=https://staffix-admin.example.com
staffix.admin-api-http.announce-username=engine
staffix.admin-api-http.announce-password=${STAFFIX_ADMIN_ENGINE_PASSWORD}
staffix.admin-api-http.announce-ssl-bundle=console-trust

management.endpoints.web.exposure.include=fix-sessions,health,info
staffix.actuator.enabled=true
staffix.actuator.fix-session-state-contributes-to-health-status=true

staffix-admin-api-http-spring-boot serves the admin API over HTTP and announces the engine to the staffix admin console; ssl-bundle names a Spring Boot SSL bundle to serve HTTPS with, announce-ssl-bundle one whose truststore trusts the console's certificate (the JVM's default otherwise), and the other settings are in Runtime administration.

staffix-alerts-publisher-slf4j-spring-boot logs alerts, declared as staffix.alerts-publishers-slf4j.instances.<key>.* and named by a session's fix-alerts-publisher-instance-id; see Alerting.

staffix-alerts-publisher-alertmanager-spring-boot sends alerts to Prometheus Alertmanager, declared as staffix.alerts-publishers-alertmanager.instances.<key>.*; ssl-bundle names a Spring Boot SSL bundle whose truststore trusts the Alertmanagers' certificates. See Alerting.

The actuator module adds a fix-sessions endpoint and can fold session state into the health status; see Runtime administration before turning that on.

Plugin wrappers compose by referencing another instance's key:

staffix.async-plugin.instances.md.wraps=md
staffix.async-plugin.instances.md.queue-size=2048
staffix.async-plugin.instances.md.consumer-thread-pool-size=1
staffix.async-plugin.instances.md.backpressure-policy=DROP

wraps takes the instance-id key of another sessions-plugin entry: a staffix.monitoring.instances.<key> or staffix.tracing.otel.instances.<key>. See Monitoring.

Note the difference from the Java API here: in properties both plugins are declared and the wrapper references the one it wraps by key, whereas in Java the wrapper contains the delegate's settings as delegateSettings and is registered in its place. Same result, and the wrapper is transparent either way: sessions go on naming the delegate.


High availability

staffix-ha-spring-boot replicates the sessions' stores to a follower engine, and staffix-ha-primos-spring-boot elects the leading engine with the node of primos-spring-boot-starter, so your own leader-only beans and the FIX sessions follow one election. See High availability for what it does and what it does not.

staffix.ha-replication.node-id=1
staffix.ha-replication.cluster-name=fix-gateway-prod
staffix.ha-replication.peers.1=fix-a.internal:17101
staffix.ha-replication.peers.2=fix-b.internal:17101
staffix.ha-replication.monitoring-instance-id=metrics
staffix.ha-replication.alerts-publisher-instance-id=alerts

# encrypts the replication: the same secret, cipher and MAC on both nodes
staffix.ha-replication.encryption.mode=required
staffix.ha-replication.encryption.secret=${STAFFIX_HA_SECRET}

# switchover and maintenance mode move a leadership the application shares, so they are off unless allowed
staffix.ha-replication.leadership-control=true
# how long before any successor's election this node's sessions are dropped; unset keeps 50ms
staffix.ha-replication.fencing-margin=50ms

# per session
…sessions[0].ha.replication-mode=SYNC_APPLIED
…sessions[0].ha.replication-ack-timeout=50ms
…sessions[0].ha.replication-quorum=1
…sessions[0].ha.sync-ack-latency-enabled=true

node-id and the peers keys are the primos node ids: primos names the leader by its id, and the replication looks that name up in peers. The other ReplicationHaSettings settings bind the same way (pair-name, log-capacity, replication-lanes, heartbeat-interval, reconnect-interval, send-buffers, snapshot-chunk-bytes, promotion-outgoing-seq-num-jump, hand-over-timeout, switchover-timeout, switchover-max-pending-writes, follower-check-interval, follower-lag-alert-threshold, follower-stall-timeout, log-full-timeout, slow-follower-hold-off, session-settings-replicated, replicated-settings-stores, sync-followers); their defaults are in the guide. sender-idle-strategy, sync-ack-idle-strategy and select-strategy take default or busy-spin; see Latency. encryption.mode takes disabled, preferred or required, beside encryption.cipher, encryption.key-bits, encryption.mac and encryption.provider.

The engine stops one lifecycle phase before the primos node, so a leader shutting down hands its sessions over before primos hands its leadership over, and its follower takes them over without moving its sequence numbers.


Extending it

The starter is built on an SPI, so a component of your own can join the same configuration model rather than being wired separately. staffix-spring-boot-spi defines the contribution points:

contributor contributes
FixMessagesStoreSettingsContributor a message store
FixMessagesLoggerSettingsContributor a message logger
FixAlertsPublisherSettingsContributor an alerts publisher
FixSessionsSettingsStoreSettingsContributor a session settings store
FixSessionsPluginSettingsContributor a session plugin
AdminApiExporterSettingsContributor an admin API exporter
FixSessionSettingsPostProcessor a last pass over every session's settings before they are used

That last one is the escape hatch: if a setting has no property yet, or you need to derive one at startup, a post processor lets you reach every session's settings in Java without giving up properties for everything else.