Writing a Message Handler Plug-in Process Function

The message handler plug-in process function (ffh_mh_process_function) for the message handler processes a decoded FAST message by mapping it into the publisher API.

Warning!  Do not modify the contents of ffh_fast_message and its members in your message-processing code.
  1. Cast the event->info->user_data field to a pointer to an instance of your message handling class, if one was created during initialization.
  2. If the event type is MHET_RECEIVE_MESSAGE, invoke the message processing methods on the message handler object and return the result.
  3. In your message handler class, examine the contents of the event->message field, which is of type ffh_fast_message.

    Based on the message type, use the publisher API to publish the message contents as described in steps four and five.

  4. Look for data required to create a RAP publisher message, then:
    1. Invoke the publisher’s pub_beginMessage API.
    2. Plug in the available data using pub_setXXXField API.
    3. Call the publisher’s pub_sendMessage API .
    4. Repeat for each publisher message contained within the ffh_fast_message.
  5. Once the entire ffh_fast_message has been processed (or if the message was not processed because an error occurred), invoke the info->release_message callback, specifying the ffh_fast_message as the argument.

    This notifies the FAST feed handler that it can release any resources associated with the given ffh_fast_message.

    In the event of an error from the publisher API or missing or incorrect data, log the error and call the publisher’s pub_cancelMessage API.

Sample process function

extern "C“ int32_t process( ffh_mh_event * event )
{
    return (( FIXMessageHandler* )
        event->info->user_data)->receiveMessage(
            event->info, event->message );
}

int32_t FIXMessageHandler::receiveMessage(
    ffh_mh_info * info,
    ffh_fast_message * fastMsg )
{
    uint32_t error_code = ERR_NONE;

    // switch based on template id of incoming FAST message
    switch( fastMsg->template_id ) {
        case QUOTE_TEMPLATE_ID:
            // start creating a RDS Stock Quote message
            pub_beginMessage( STOCK_QUOTE_MSG, _msg_ctx );
            // use Publisher API pub_setXXXField() calls 
            // to populate its fields based on fastMsg
            // contents
            ...
            break;
	       // handle other message types here
		      case ...
    }

    if( error_code != ERR_NONE ) {
        // error processing the FAST message, cancel it
        pub_cancelMessage( _msg_ctx );
    } else {
        // successfully processed the FAST message,
        // publish it
        error_code = pub_sendMessage( _msg_ctx );
    }

    // release no longer needed FAST message
    info->release_message( info, fastMsg );
    return error_code;
}
Related concepts
Message Handler Plug-ins
Related tasks
Writing a Message Handler Plug-in for the FAST Feed Handler
Writing a Message Handler Plug-in Initialize Function
Writing a Message Handler Plug-in Finalize Function
Implementing the Shutdown Callback Method
Related reference
Arguments of the Message Handler Plug-in Initialize Function
Arguments of the Message Handler Process Function
Arguments of the Message Handler Finalize Function
C API Definitions of Function Signatures for Building a Message Handler
C API Definition of ffh_fast_message and its Related Structures
FAST Templates