Skip to content

KdbPublisher

Jas edited this page Mar 14, 2017 · 1 revision

KdbPublisher and KdbPublisherThread

These classes provide the ability to publish updates to a kdb+ process (via .u.upd) asynchronously.

The publisher also supports auto-reconnection to the kdb+ process after a configurable amount of time has passed since the last publish to the process. This is to improve publish reliability when the connection is dropped remotely and Java does not detect it.

KdbPublisherThread simply wraps KdbPublisher into its own thread to take the processing of the update messages from the constructing thread. The thread is started automatically as part of the object construction.

Configuration

To configure the publisher you need to specify the target kdb+ process to publish to (using a KdbProcess object).

By default, the standard inactive reconnection interval is 30 minutes. This means if there has been no data published for 30 minutes, then the publisher automatically reconnects to the target process prior to sending the data. To modify this, use the Joda time Duration class (e.g. Duration.standardMinutes(30)).

Usage

You can send data to be published either in KdbTable form (which is recommended) or in Flip form:

  • publish(KdbTable)
  • publish(List<KdbTable>)
  • publish(String, Flip) requires the table name as well as the table data to be passed

Each publish function returns a boolean (or list of booleans) to inform you if the publish was successful or not. Note that because the publish is done asynchronously this is only detecting send errors from the Java side, not that the kdb process processed the data correctly.

Example

public KdbPublisherThread startPublisher() throws KdbTargetProcessUnavailableException {
    KdbProcess target = new KdbProcess("localhost", 54321);

    return new KdbPublisherThread(target);
}

// Example publish, connect / publish / disconnect in single function
public void publishSomething() {
    KdbPublisherThread publisher = startPublisher();

    KdbTable emptyTable = new KdbTable("trade");

    publisher.publish(emptyTable);

    publisher.disconnect();
}
Clone this wiki locally