Use the Publisher API, the logging API, and configuration files to develop and deploy a custom feed handler. Use the
demo feed handler as an example, in addition to examples in the documentation.
Prerequisites
Create or modify message templates and modify the corresponding RAPCache and RAPStore database schemas, either manually or using RAP message modeling.
If you model messages, you can generate Publisher API stubs to automate some of the steps in this task.
-
Define and invoke the required data structures:
- PUB_CALLBACKS structure for callbacks used in shutdown processing.
- PUB_STARTUP structure for initialization.
- PUB_SEND_MESSAGE_CONTEXT structure for each market data message to be built simultaneously.
For example, the demo feed handler, which can send only one message at a time, creates exactly one PUB_SEND_MESSAGE_CONTEXT and reuses it. If it sent two at a time, it would need two separate PUB_SEND_MESSAGE_CONTEXT structs.
-
Initialize the publisher.
Call pub_initialize to perform initialization tasks, using settings in publisher.xml.
Invoke a custom configuration file for any additional settings.
-
Set up messages to be sent.
- Call pub_beginMessage to indicate the start of a new message.
- For each field in the message, call the appropriate pub_set<type>Field method for your data.
- Call pub_sendMessage to send the message to the buffer, or call pub_cancelMessage to abandon the message.
Messages are buffered until a packet is full, and then sent over the network.
-
Add error checking and logging. Use either:
- The logging API methods, or
- Your own logging functions.
The installation includes some examples for the logger.
-
(Optional) Explicitly send any buffered messages to the subscribers. Either:
- Call pub_flush to flush messages, or,
- Use the bool flush parameter of pub_shutdown.
-
Process shutdown requests:
- Perform any feed handler activities that must occur prior to shutdown. This may include finishing building messages in progress.
- Implement the shutdown callback method used in the PUB_CALLBACKS structure. This shutdown method should ensure that message publishing stops, that resources initialized are freed and returned to the system, and that pub_shutdown is called.
- (Optional) Call pub_cancelMessage to cancel any messages being built and free resources.
- Call pub_shutdown to disconnect from the network and discard any resources being used.
For example, at a high level, the main() method in the demo feed handler does the following:
pub_initialize()
as long as the variable _continue is true
read a line from the input file, wrapping to the top if necessary
use that information to publish a message
go back to the top of the loop
pub_shutdown
The callback shutdown method sets _continue to false, which causes the main method to stop and call pub_shutdown.
Next
Define configuration files.
Create a shell script to invoke the feed handler, and set up your environment to recognize it.
Compile and test the feed handler.