baron
baron

Reputation: 179

quickfixj initiator manually resend reset to a seqnum at logon

I have a quickfixj initiator connecting to vendor's acceptor and receiving messages. I keep the fix messages in a buffer which is processed by a thread. To avoid loosing the message in case crash with message in the buffer, I have the last seqnum processed, and plan to send resend message for that next seqnum on my side when I reconnect. I know the better solution would be that I save the messages before I receives them, but the design is to avoid doing any db access in the onMessage call. I didn't find any example how this could be done, resending request for a specific seqnum. Should I simply overload the logon message and send the seqnum? Anyone has an example?

Upvotes: 2

Views: 2165

Answers (1)

Hemant Singh
Hemant Singh

Reputation: 1598

I guess you are already in synch as per the last thread if quickfixj crash in onmessage, will I lose my current message?.

QuickFixJ manages 2 sequence numbers:

  1. SenderSequenceNum: Sequence number used in sending messages.
  2. TargetSequenceNum: Sequence number expected to receive.

So you have two options:

Option 1: Process the receive messages on the QuickfixJ onMessage() callback thread. So that in case of an exception the sequence number does not increment. And QuickFixJ automatically sends the resend request on receiving next fix message as it will detect the sequence gap.

Option 2: Persist the sequence number that you have successfully processed. In case of crash, on restart you can set the expected receive sequence number using:

Session.lookupSession(session_).setNextTargetMsgSeqNum();

So if you receive a sequence number higher than that, QuickfixJ automatically sends resend the request.

Note: Do not change the sender sequence number then another party will receive a sequence number lower than expected and can cause disconnection.

Upvotes: 1

Related Questions