This repository was archived by the owner on Aug 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
HowTo: Subscription
michaelwittig edited this page Oct 26, 2014
·
6 revisions
kdb+tick brings a mechanism to publish/subscribe data. Mostly you will publish parts of a table. Other Q processes can open a connection to the publisher and subscribe for interessting data. More information is given here.
- Define the listener.
// static table definition
final MyTable table = MyTable.get();
QConnectorListener listener = new QConnectorListener() {
@Override
public void exception(QConnectorException e) {
// ...
}
@Override
public void error(QConnectorError e) {
// ...
}
@Override
public void resultReceived(String handle, Result result) {
for (final TableRow row : table.read(result)) {
System.out.println(row.get(table.time()));
System.out.println(row.get(table.sym()));
System.out.println(row.get(table.price()));
System.out.println(row.get(table.size()));
}
}
}; - Create and start the connector
QConnectorAsync c = QConnectorFactory.create(listener , "localhost", 5010, true);
c.connect();- Subscribe to trades and quotes for the Smbols FGBL, FGBM and FGBS.
c.subscribe("MyFirstSub", new String[] {"mytable"}, new String[] {"FGBL", "FGBM", "FGBS"});- Just wait a couple of seconds and then close the connection.
Thread.sleep(1000 * 1000);
c.disconnect();