Fault Tolerance
Backup Session
The backup session must use the same Universally Unique Identifier (UUID) as the primary session.
Before establishing the connection with the backup Market Segment Gateway, set
Fault
Note
A backup session must be ready to activate in the same data state as the previous primary session being replaced. For example, inbound and outbound sequence numbers for a UUID must be maintained in a consistent state during failover between both sessions.
See Also
The Fault Tolerance CME article.
Primary Session Failure
If the exchange does not receive a message from the primary session within two times
the Keep
- Both the primary and backup sessions will be disconnected from the exchange, the backup session will receive the Terminate message.
- The backup session will be expected to connect to the primary Market Segment Gateway.
Primary Market Segment Gateway Failure
If the primary Market Segment Gateway Gateway fails, then the exchange initiates failover by electing the backup Market Segment Gateway to assume the primary role.
The backup session connected to this newly chosen Market Segment Gateway must act as the primary one. It is notified about the failover via the Failover event.
After the failover the Fault
Example
void OnFailover(object sender, FailoverEventArgs args)
{
Console.WriteLine($"Primary Market Segment Gateway Failure, faultToleranceIndicator={args.FaultToleranceIndicator}.");
((Session)sender).InSeqNum = lastKnownPrimarySessionInSeqNum;
((Session)sender).OutSeqNum = lastKnownPrimarySessionOutSeqNum;
}
void OnInboundSessionMessage(object sender, InboundMessageEventArgs args)
{
const int TerminateTemplateId = 507;
if (args.Message.TemplateID == TerminateTemplateId)
{
const int ErrorCodesTag = 39012;
const int DisconnectFromPrimary = 26;
if (args.Message.GetUnsignedShort(ErrorCodesTag) == DisconnectFromPrimary)
{
Console.WriteLine("Primary Session Failure.");
}
}
}
using Session primary = new(settings, marketSegmentId);
primary.Failover += OnFailover;
primary.InboundSessionMessage += OnInboundSessionMessage;
primary.Connect(PrimaryGateway, GatewayPort);
using Session backup = new(settings, marketSegmentId, uuid: primary.SessionId.Uuid, customKey: "BackupSession");
backup.Failover += OnFailover;
backup.InboundSessionMessage += OnInboundSessionMessage;
backup.FaultToleranceIndicator = FaultToleranceIndicator.Backup;
backup.Connect(BackupGateway, GatewayPort);