Subscription

This section explains how to subscribe to streaming data and the associated operations through DolphinDB C++ API.

Subscription Option

The DolphinDB C++ API provides three classes to subscribe to streaming data: ThreadedClient, ThreadPooledClient, and PollingClient. To quickly find out the appropriate mode for your scenario, refer to the table provided below.

Class Scenario
ThreadedClient produces a single thread that calls for a user-defined handler on incoming message(s)
ThreadPooledClient produces multiple threads that poll and call a user-defined handler simultaneously on each incoming message
PollingClient returns a message queue, from which user can retrieve and process the messages

Message Class

When the API receives a subscribed message from DolphinDB, it will be encapsulated into a Message class instance. You can process Message objects with user-defined function (handler).

The Message class is a subclass of ConstantSP, so the method of retrieving data from a Message object is the same as reading data from a ConstantSP object. You can refer to Data Objects for instructions on how to access the data within Message objects.

There are two unique functions of the Message class.

getSymbol

When subscribing to a heterogeneous stream table, you can use the getSymbol function to retrieve the symbol identifier. This symbol can be used to determine the source table from which the received message originates. For more information, refer to Heterogeneous Stream Table Subscription.

The function declaration is as follows:

const std::string& getSymbol();

getOffset

You can use the getOffset function to obtain the offset of the message within the table (starting from 0).

The function declaration is as follows:

int getOffset();

Note: This function only takes effect when the filter parameter is not specified.