This article will discuss how to build a real-time request-response API using ClearConnect.
An example scenario that we will use is an electronic card checking system, such as one used on many undergrounds. There are many terminals controlling access to the underground and each terminal needs to scan a card, query a central system for details and then determine whether the card is valid for entry. In this article we will
- Work through defining the API used by the terminals to query the credentials of a scanned card.
- Implement the API using ClearConnect.
- Define the skeleton of the service that supports the API (we will not actually be building the full card checking system).
The diagram below illustrates the scenario
The API is quite simple, we will have one method that is used to lookup the credentials of a card and an object that represents the card credentials:
Implementing the API
This is the code that provides the API implementation.
As you can see, with very little code the API (albeit a single method API) has been implemented for clients to call. Next we look at the server-side.
What about threading?
ClearConnect manages a pool of threads dedicated for running RPC handler code. The number is fixed and scales with the number of available CPUs. This can be overridden using the system property dataFission.rpcThreadCount=[number of threads]
This article has shown how a request-response API can be implemented using the ClearConnect platform. The RPC mechanics are simple to use and provide a very transparent manner for writing logic that needs to be invoked remotely.