Skip to main content

Dynamic Subscription Change

TimeBase allows subscribing to live data based on message attributes such as type, stream and symbol and changing subscription at any time.

There are three possible scenarios:

Basic Subscription

In the Basic scenario, subscription starts at some point of time (close to real-time) when the command reaches the server. This scenario may be applied in case precise subscription timing and order are not critical.

Basic subscription options
//Subscribe to a symbol
cursor.removeEntity(new ConstantIdentityKey("CLX20"));
cursor.addEntity(new ConstantIdentityKey("CLZ20"));

//Sybsrcibe to a message type

//Subscribe to a stream
TickStream stream =
.filter(item -> "SmartMetersOhio".equals(item.getKey()))
.orElseThrow(() -> new IllegalStateException("Stream was not found"));

Precise Subscription

Precise subscription may be applied when it is necessary to set the precise timing for a new subscription. In this case, the subscribed data arrives precisely at the specified time but there is no guarantee as for the data ordering.

Precise subscription
// specify time for newly subscribed data
cursor.addEntity(new ConstantIdentityKey("TrafficLight-4419"));

Complete Reset

This scenario may be applied in case both precise subscription timing and order are required. It is the slowest case in terms of performance due to the complete reset of all buffers. Reset is performed at a specified time, starting from which you will receive data with the precise order and time.

Subscribe for precise order and time
// reset cursor
String[] symbolsToAdd = new String[] {"Meter-1", "Meter-2", "Meter-3"};
.map(item -> new ConstantIdentityKey(item))
.toArray(IdentityKey[]::new), 0, symbolsToAdd.length);