Incoming FIX Message Callback

QWFIX allows application to register specific message handlers for specific group of message types. Application should also register a "default" handler to process the rest of the (including unexpected) message types.

The message handler contains callbacks for each incoming message. It also contains callback for each outgoing message, which is only triggered during recovery process.

In this example, we create two message handlers. One special message handler to process "Allocation" related FIX messages and one default message handler to process messages with other message types.

Note: The operation is usually performed in a FIXStandaloneApplication.FIXEngineInitialized event handler.

CopyCode in FIXEngineInitialized Event Handler
static void OnFIXEngineInitialized(FIXEngine engine)
{
    IFIXEngineMessageHandler myAllocationMessageHandler = new MyAllocationMessageHandler();
    IFIXEngineMessageHandler myDefaultMessageHandler = new MyDefaultMessageHandler();
    foreach (FIXSession curSession in engine.Sessions)
    {
        // Register the message handler for the "Allocation" related message types.
        // Note, "Reject" or "BusinessMessageReject" messages against these message types will also be sent to the
        // handler, even though they are not included explicitly.
        engine.SetEngineMessageHandler(curSession,
            myAllocationMessageHandler, 
            MsgTypes.AllocationInstruction, 
            MsgTypes.AllocationInstructionAck,
            MsgTypes.AllocationReport,
            MsgTypes.AllocationReportAck);
        engine.SetEngineMessageDefaultHandler(curSession, myDefaultMessageHandler);
    }
    // TODO: Other code
}

The sample definition of message handlers.

CopyMessage Handlers
class MyAllocationMessageHandler : IFIXEngineMessageHandler
{
    public void OnMessageSent(FIXMessage message, FIXEngineMessageHandlerStatus status)
    {
        // Note: This method is only called during recovery process.
        // TODO:
    }

    public void OnMessageReceived(FIXMessage message, FIXEngineMessageHandlerStatus status)
    {
        // TODO:
    }
}

class MyDefaultMessageHandler : IFIXEngineMessageHandler
{
    public void OnMessageSent(FIXMessage message, FIXEngineMessageHandlerStatus status)
    {
        // Note: This method is only called during recovery process.
        // TODO:
    }

    public void OnMessageReceived(FIXMessage message, FIXEngineMessageHandlerStatus status)
    {
        // TODO:
    }
}

Application can retrieve the message token (FIXMessage.MessageToken) from the incoming message. The token can be kept and used to access the message in the future. Application should NEVER directly keep the reference of the message. It should use the message token instead!

See Also:

IFIXEngineMessageHandler
FIXEngine.SetEngineMessageHandler
FIXEngine.SetEngineMessageDefaultHandler
FIXMessage.MessageToken