Example: Building a Market Data Message

Use methods offered by the publisher API that have the feed handler build a message to send to the RAP system.

The following sample code builds a market data message.
Note: For simplicity, error checking has been omitted from this example; however, production code should include error checking.
	  PUB_CALLBACKS * callbacks;
	  PUB_STARTUP * startup;
	  PUB_SEND_MESSAGE_CONTEXT * msg;
	  uint16_t error_code;		
		 callbacks = Allocate a PUB_CALLBACKS structure;
		 callbacks->shutdown = &myShutdownEventReceiver;		
		 startup = Allocate a PUB_STARTUP structure;
		 startup->config_dir = configuration file directory or null;
		 startup->template_dir = “templates”;
		 startup->strict_check = false;
		 startup->component_subtype = “FAST Feed Handler”;
		 startup->callbacks = callbacks;
   startup.version = PUB_STARTUP_VERSION;	
   pub_initialize( startup );
	  msg = Allocate a PUB_SEND_MESSAGE_CONTEXT structure;
	  loop for each message {
		    error_code = pub_beginMessage( <message_type>, msg );
		    error_code = pub_setInt32Field( msg, <field_name>, <field_value> );
		    error_code = pub_setStringField( msg, <field_name>, <field_value> );
		    error_code = pub_setInt16Field( msg, <field_name>, <field_value> );
		    error_code = pub_sendMessage( msg );
   }	
	  error_code = pub_flush();	
		 error_code = pub_shutdown( false );
   Free the PUB_SEND_MESSAGE_CONTEXT structure;
   Free the PUB_CALLBACKS structure;

To build multiple messages simultaneously, allocate several PUB_SEND_MESSAGE_CONTEXT structures and use one structure per message. Only one call should initialize the publisher, not one per thread. Similarly, make only a single call to shut down the publisher.

The feed handler does not need to call flush. This call is optional. The shutdown API accepts a Boolean parameter that indicates whether to flush any buffered messages before shutting down.

Related concepts
Feed Handler Shutdown
Application Development Using Publisher API Stubs
publish_<msgName>_Message() Stub
Related tasks
Testing a Custom Feed Handler
Debugging a Custom Feed Handler
Deploying a Custom Feed Handler
Developing with the publish_<msgName>_Message() Stub
Related reference
Supported Datatypes for Message Flow