Skip to main content

Code Examples

The client-sample.tar.gz file contains a multi-module Maven project that is made up of a number of examples.

Setup​

  1. When running samples the following JVM args must be specified:
--add-opens java.base/jdk.internal.misc=ALL-UNNAMED
  1. The samples contain a ks-common project that has a TutorialConstants class - update the KEY_ACCESS_URL constant to point to your development environment.

Examples​

Each example can be found within its own maven module labelled by the name.

Hello World​

This example shows a very simple pair of applications that subscribe to and publish a Java Map.

ClassDescription
trading.keysquare.tutorial.helloworld.HelloWorldSubscriberA basic application that subscribes to a Java Map.
trading.keysquare.tutorial.helloworld.HelloWorldPublisherA basic application that publishes a Java Map.

When running the two examples, the published data can be seen using the Viewer.

Using the Viewer, select the KsCore model:

ks platform model

Double click on the Flexible row, which will show the data being published:

flexible

Serialization​

This example shows how the API can be used to publish / subscribe to the different forms of serialization:

  • Java Map
  • Java Pojo
  • Data Transfer Object (DTO) which adheres to SBE schema
  • Simple Binary Encoding (SBE)
ClassDescription
trading.keysquare.tutorial.serialization.SerializationSubscriberSubscribes to the variety of serialization formats.
trading.keysquare.tutorial.serialization.SerializationPublisherPublishes the variety of serialization formats.

Demo Pricer​

This example shows a more complex example where a custom model is being created within the project and used by two processes.

ClassDescription
trading.keysquare.tutorial.demopricer.DemoPricePublisherCreates and publishes a random bid/offer for a single price.
trading.keysquare.tutorial.demopricer.DemoPriceEngineConsumes the price published by the DemoPricePublisher and adds a spread to that price and re-publishes it out as a new source.

When running the two pricer examples, the published data can be seen using the Viewer.

Using the Viewer, select the DemoPricerModel:

demo price model

Double click on the DemoPrice row, which will show the data being published:

demo pricer

Coming soon...

info

The following topics will be covered shortly...

KeySessionListener​

  1. Life cycle, start, stop, connected, disconnected
  2. Unrouted messages

Monitoring​

  1. Counter
  2. Histogram

Misc​

  1. Session.getApplicationId, Session.getApplicationName
  2. Optional: Key application
  3. Optional: Config
  4. SBE backwards compatibility rules

Message Editing​

  1. Editable flag
  2. Requesting edits
  3. Receiving edits
  4. Best practices - overlay over existing message

Topic Sets​

  1. How to create
  2. How to subscribe

Message Store​

  1. Storing messages
  2. Message Store modes
  3. Retrieving messages
  4. Deleting messages

Resiliency​

  1. Auto reconnect

The Real World​

  1. Real World Example