esanchezros / quickfixj-spring-boot-starter

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

Logs are not stored in Database using Spring JPA #134

Closed nurrony closed 3 months ago

nurrony commented 3 months ago

I am using Postgres with Spring Boot 3.2.4 along with Spring Data JPA and configured MessageStoreFactory and LogFactory as follows


@Configuration
public class MyFixClientConfig {

    @Bean
    public Application clientApplication(final SessionSettings sessionSettings) {
        return new MyQuickfixApplication(sessionSettings);
    }

    @Bean
    public Initiator clientInitiator(Application clientApplication,
            MessageStoreFactory clientMessageStoreFactory,
            SessionSettings clientSessionSettings, 
            LogFactory clientLogFactory,
            MessageFactory clientMessageFactory) throws ConfigError {

        return new ThreadedSocketInitiator(clientApplication, clientMessageStoreFactory, clientSessionSettings, clientLogFactory, clientMessageFactory);
    }

    @Bean
    public MessageStoreFactory clientMessageStoreFactory(SessionSettings clientSessionSettings, DataSource dataSource) {
        JdbcStoreFactory jdbcStoreFactory = new JdbcStoreFactory(clientSessionSettings);
        jdbcStoreFactory.setDataSource(dataSource);
        return jdbcStoreFactory;
    }

    @Bean
    public LogFactory clientLogFactory(SessionSettings clientSessionSettings, DataSource dataSource) {
        JdbcLogFactory jdbcLogFactory = new JdbcLogFactory(clientSessionSettings);
        jdbcLogFactory.setDataSource(dataSource);
        return jdbcLogFactory;
    }
}

My Quicfix/J config

JdbcLogHeartBeats=N
UseJDBCLogger=Y
JdbcUser=postgres
JdbcPassword=****
JdbcDriver=org.postgresql.Driver
JdbcURL=jdbc:postgresql://localhost/oms_orders?currentSchema=client
JdbcLogEventTable=fix_event_log
JdbcSessionIdDefaultPropertyValue=NULL
JdbcStoreMessagesTableName=fix_messages
JdbcStoreSessionsTableName=fix_sessions
JdbcLogIncomingTable=fix_messages_log_incoming
JdbcLogOutgoingTable=fix_messages_log_outgoing

In application.yaml I use these settings

spring:
  datasource:
    username: ${POSTGRES_USER}
    password: ${POSTGRES_PASSWORD}
    url: jdbc:postgresql://localhost/oms_orders?currentSchema=client
    driver-class-name: org.postgresql.Driver

# QuickfixJ settings
quickfixj:
  client:
    enabled: true
    jmx-enabled: true
    config: ${QUIICKFIXJ_CLIENT_CONFIG_FILE:classpath:quickfixj-client.cfg}
    message-store-factory: jdbc
    log-factory: jdbc

What I am doing wrong? Please help me. Thanks in advance

esanchezros commented 3 months ago

Hi @nurrony

Do you have the project in a github repo I can access? Could you also send the db schema? I'll have a look in a bit

nurrony commented 3 months ago

@esanchezros thanks for your quick reply. Here is the db schemas. I do not have it in github yet. Please give me some time to put this on GitHub.

CREATE TABLE "client"."fix_event_log" (
    "id" int8 NOT NULL DEFAULT nextval('client.fix_event_log_id_seq'::regclass),
    "beginstring" varchar(8),
    "sendercompid" varchar(64),
    "senderlocid" varchar(64),
    "sendersubid" varchar(64),
    "session_qualifier" varchar(64),
    "targetcompid" varchar(64),
    "targetlocid" varchar(64),
    "targetsubid" varchar(64),
    "text" text,
    "time" timestamp,
    PRIMARY KEY ("id")
);

CREATE TABLE "client"."fix_messages" (
    "beginstring" varchar(8) NOT NULL,
    "msgseqnum" int4 NOT NULL,
    "sendercompid" varchar(64) NOT NULL,
    "senderlocid" varchar(64) NOT NULL,
    "sendersubid" varchar(64) NOT NULL,
    "session_qualifier" varchar(64) NOT NULL,
    "targetcompid" varchar(64) NOT NULL,
    "targetlocid" varchar(64) NOT NULL,
    "targetsubid" varchar(64) NOT NULL,
    "message" text,
    PRIMARY KEY ("beginstring","msgseqnum","sendercompid","senderlocid","sendersubid","session_qualifier","targetcompid","targetlocid","targetsubid")
);

CREATE TABLE "client"."fix_messages_log_incoming" (
    "id" int8 NOT NULL DEFAULT nextval('client.fix_messages_log_incoming_id_seq'::regclass),
    "beginstring" varchar(8),
    "sendercompid" varchar(64),
    "senderlocid" varchar(64),
    "sendersubid" varchar(64),
    "session_qualifier" varchar(64),
    "targetcompid" varchar(64),
    "targetlocid" varchar(64),
    "targetsubid" varchar(64),
    "text" text,
    "time" timestamp,
    PRIMARY KEY ("id")
);

CREATE TABLE "client"."fix_messages_log_outgoing" (
    "id" int8 NOT NULL DEFAULT nextval('client.fix_messages_log_outgoing_id_seq'::regclass),
    "beginstring" varchar(8),
    "sendercompid" varchar(64),
    "senderlocid" varchar(64),
    "sendersubid" varchar(64),
    "session_qualifier" varchar(64),
    "targetcompid" varchar(64),
    "targetlocid" varchar(64),
    "targetsubid" varchar(64),
    "text" text,
    "time" timestamp,
    PRIMARY KEY ("id")
);

CREATE TABLE "client"."fix_sessions" (
    "beginstring" varchar(8) NOT NULL,
    "creation_time" timestamp NOT NULL,
    "incoming_seqnum" int4 NOT NULL,
    "outgoing_seqnum" int4 NOT NULL,
    "sendercompid" varchar(64) NOT NULL,
    "senderlocid" varchar(64) NOT NULL,
    "sendersubid" varchar(64) NOT NULL,
    "session_qualifier" varchar(64) NOT NULL,
    "targetcompid" varchar(64) NOT NULL,
    "targetlocid" varchar(64) NOT NULL,
    "targetsubid" varchar(64) NOT NULL,
    PRIMARY KEY ("beginstring","creation_time","incoming_seqnum","outgoing_seqnum","sendercompid","senderlocid","sendersubid","session_qualifier","targetcompid","targetlocid","targetsubid")
);
nurrony commented 3 months ago

@esanchezros here is the sample project with same configuration https://github.com/nurrony/simple-fix-client

esanchezros commented 3 months ago

Hi @nurrony

I had a look at the quickfix config and spring config classes and all I can think of right now is that you may have to use either use one or the other. I'm not at home at the moment but I'll have a go at your code tonight

nurrony commented 3 months ago

@esanchezros I couldn't appreciate it more. Please don't ruin your weekend :) .

esanchezros commented 3 months ago

In application.yml set:

hikari:
  auto-commit: true

Also, set JdbcLogHeartBeats=Y so you'll see the heartbeats recorded.

id,beginstring,sendercompid,senderlocid,sendersubid,session_qualifier,targetcompid,targetlocid,targetsubid,text,time
21,FIXT.1.1,BANZAI,NULL,NULL,NULL,EXEC,NULL,NULL,8=FIXT.1.19=7835=A34=149=BANZAI52=20240518-21:19:06.14756=EXEC98=0108=30141=Y1137=710=160,2024-05-18 23:19:10.762000
22,FIXT.1.1,BANZAI,NULL,NULL,NULL,EXEC,NULL,NULL,8=FIXT.1.19=5335=534=249=BANZAI52=20240518-21:19:24.13956=EXEC10=008,2024-05-18 23:19:24.145000
23,FIXT.1.1,BANZAI,NULL,NULL,NULL,EXEC,NULL,NULL,8=FIXT.1.19=7835=A34=149=BANZAI52=20240518-21:20:17.29856=EXEC98=0108=30141=Y1137=710=161,2024-05-18 23:20:21.111000
24,FIXT.1.1,BANZAI,NULL,NULL,NULL,EXEC,NULL,NULL,8=FIXT.1.19=5335=034=249=BANZAI52=20240518-21:20:48.28456=EXEC10=002,2024-05-18 23:20:48.293000
25,FIXT.1.1,BANZAI,NULL,NULL,NULL,EXEC,NULL,NULL,8=FIXT.1.19=5335=034=349=BANZAI52=20240518-21:21:18.28256=EXEC10=255,2024-05-18 23:21:18.286000
26,FIXT.1.1,BANZAI,NULL,NULL,NULL,EXEC,NULL,NULL,8=FIXT.1.19=5335=034=449=BANZAI52=20240518-21:21:48.28256=EXEC10=003,2024-05-18 23:21:48.290000
27,FIXT.1.1,BANZAI,NULL,NULL,NULL,EXEC,NULL,NULL,8=FIXT.1.19=5335=034=549=BANZAI52=20240518-21:22:18.28256=EXEC10=002,2024-05-18 23:22:18.286000
28,FIXT.1.1,BANZAI,NULL,NULL,NULL,EXEC,NULL,NULL,8=FIXT.1.19=5335=034=649=BANZAI52=20240518-21:22:48.28256=EXEC10=006,2024-05-18 23:22:48.290000
29,FIXT.1.1,BANZAI,NULL,NULL,NULL,EXEC,NULL,NULL,8=FIXT.1.19=5335=034=749=BANZAI52=20240518-21:23:18.28256=EXEC10=005,2024-05-18 23:23:18.289000
30,FIXT.1.1,BANZAI,NULL,NULL,NULL,EXEC,NULL,NULL,8=FIXT.1.19=5335=034=849=BANZAI52=20240518-21:23:48.28256=EXEC10=009,2024-05-18 23:23:48.290000
31,FIXT.1.1,BANZAI,NULL,NULL,NULL,EXEC,NULL,NULL,8=FIXT.1.19=5335=034=949=BANZAI52=20240518-21:24:18.28256=EXEC10=008,2024-05-18 23:24:18.290000
32,FIXT.1.1,BANZAI,NULL,NULL,NULL,EXEC,NULL,NULL,8=FIXT.1.19=5435=534=1049=BANZAI52=20240518-21:24:29.28756=EXEC10=061,2024-05-18 23:24:29.292000
33,FIXT.1.1,BANZAI,NULL,NULL,NULL,EXEC,NULL,NULL,8=FIXT.1.19=7835=A34=149=BANZAI52=20240518-21:24:38.78156=EXEC98=0108=30141=Y1137=710=165,2024-05-18 23:24:38.816000
34,FIXT.1.1,BANZAI,NULL,NULL,NULL,EXEC,NULL,NULL,8=FIXT.1.19=5335=034=249=BANZAI52=20240518-21:25:08.89056=EXEC10=006,2024-05-18 23:25:08.893000
35,FIXT.1.1,BANZAI,NULL,NULL,NULL,EXEC,NULL,NULL,8=FIXT.1.19=5335=034=349=BANZAI52=20240518-21:25:38.89156=EXEC10=011,2024-05-18 23:25:38.894000
nurrony commented 3 months ago

It works like a charm. Many many thanks for the quickest reply I have ever got from an OSS maintainer.