Resending Messages
When the Resend Request message is received from the counterparty (e.g., due to a sequence number mismatch), MessageResending event is raised if the application has been subscribed to this event. Otherwise, the SequenceReset-GapFill message will be sent instead of the requested message.
If the sent application-level message needs to be resent to the counterparty, then the
AllowResending property of MessageResendingEventArgs parameter should be set to true
while handling the event.
Otherwise, the SequenceReset-GapFill message will be sent instead (e.g., in case of an old order).
The message that is about to be resent is available via the Message property of the MessageResendingEventArgs parameter.
For example:
var session = new Session("SenderCompID", "TargetCompID", ProtocolVersion.Fix44);
session.MessageResending += OnMessageResending;
void OnMessageResending(object sender, MessageResendingEventArgs e)
{
Console.WriteLine("Resend request for message {0}", e.Message);
e.AllowResending = !IsStale(e.Message);
Console.WriteLine("AllowResending=" + e.AllowResending);
}
bool IsStale(Message message)
{
// Simple sending time-based filtering of stale messages.
DateTime previousSendingTime = message.GetTimestamp(Tag.SendingTime);
TimeSpan threshold = TimeSpan.FromMinutes(30);
return (DateTime.UtcNow - previousSendingTime) > threshold;
// More advanced filtering could take into account the message type and/or application-level content.
}
Resending Queue Size
The ResendingQueueSize parameter specifies how much messages can be resent if counterparty will request them. For example, this parameter is
set to 1000
, and counterparty sends a ResendRequest message with sequence numbers rage 1-2000
. In this case, the session will send a
SequenceReset-GapFill (4) message for range 1-1000
and messages with sequence numbers from 1001
to 2000
will be resent.
If this parameter is zero, no messages will be resent.
Message Gap Handling Modes
Per the FIX protocol there are two options for dealing with gaps:
- Request all messages including the last message received.
- Request for the specific message missed while maintaining an ordered list of all newer messages.
The default behavior of the FIX Engine corresponds to the first option. In this mode, when a sequence gap is detected, the FIX Engine sends Resend Request for all messages and waits for the reply. All newer incoming messages are ignored until the reply is received. To report the new messages anyway, use the ReportNewMessagesWhileWaitingForMissedMessages property. After the reply is received (first message with the PossDupFlag flag), there should not be any newer original messages until all requested messages are received; otherwise, each such a message will cause a new resend request. Therefore, it can increase the network load and make difficulties for the sequence synchronization.
To activate the second option of the resend functionality, set the RequestOnlyMissedMessages property to true
.
In this mode, when a sequence gap is detected, the FIX Engine sends the
Resend Request only for missed messages.
All newer incoming messages are stored in the incoming message gap queue, and they are processed when all requested messages are received.
To limit the size of this queue, use the IncomingMessageGapQueueMaximumSize setting.
See Also
- The ResendingMessages sample from the FIX Engine distribution package