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 FIXStandaloneApplicationListener.engineInitialized event handler.

    FIXStandaloneApplicationListener applicationListener = new FIXStandaloneApplicationListener() {
        public void engineInitialized(FIXEngine engine) {
            for (FIXSession curSession : engine.getSessions()) {
                // 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
        }

        public void engineRecovered(FIXEngine engine) {
            // TODO Auto-generated method stub
        }

        public void engineStarted(FIXEngine engine) {
            // TODO Auto-generated method stub
        }

        public void engineStopped(FIXEngine engine) {
            // TODO Auto-generated method stub
        }

        public void engineStopping(FIXEngine engine) {
            // TODO Auto-generated method stub
        }

        public void fatalErrorOccurs(Exception e) {
            // TODO Auto-generated method stub
        }
    };
    
    FIXEngineMessageHandler myAllocationMessageHandler = new FIXEngineMessageHandler() {
        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:
        }
    };
    
    FIXEngineMessageHandler myDefaultMessageHandler = new FIXEngineMessageHandler() {
        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.getMessageToken()) 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!