Piper Push Cache Documentation Download Samples Contact  


NATS is a high performance, open source messaging service. NATS messages can be used to update the JSON cache in Piper Push Cache. The approach taken to provide this functionality is to make Piper a subscription only client that listens to specific subjects. Messages recieved on the configured subjects are used to updated the cache.

Each subscription consists of a subject and a method of forming an record identifier for the received JSON message. If the message is not JSON or if the record identifier can not be formed then an error is logged and no cache update is performed. If a null JSON is received then the record associated with the record identifier is deleted.

Configuration of the NATS subscriber is found under the 'nats' element in the configuration file.

    "nats": {
        "active": false,
        "url": "nats://localhost:4222",
        "timeout": 2.0,
        "name": "",
        "verbose": false,
        "pedantic": false,
        "ping": {
            "interval": 2.0,
            "max_out": 3
        "reconnect": {
            "allow": true,
            "max": 10,
            "wait": 2.0
        "max_pending": 300,
        "subscriptions": [
                "subject": "sample.>",
                "id": "xyz-$e-$t-$(id)",
                "id_key": "id"

The parameter descriptions are:

active Flag indicating wether NATS messages should be used to update the cache. True turns on the feature and false turns it off.
url The URL to the NATS server. The URL can contains the user and password if they are needed. Examples are nats://localhost:4222 and nats://user@password@localhost:4222.
timeout The number of seconds before giving up trying to reconnect to the NATS server.
name Used when connecting to the NATS server.
verbose If true verbosity is turned on.
pedantic Turns on pedantic mode if true.
ping.interval The interval in seconds between pings from the client to the server.
ping.max_out The number of pings without a response allowed before closing a connection to the NATS server.
reconnect.allow If true reconnection attempts are allowed.
reconnect.max Maximum number of reconnect attempts.
reconnect.wait The number of seconds to wait between reconnect attempts.
max_pending Maximum number of message that can be buffered before the connection is deem to be a slow consumer.
subscriptions An JSON array of subscription objects.

The elements in the subscriptions array must be JSON objects and have two members.

subject The NATS subject to subscribe to.
id The template for record identifiers. The following patterns as well as simple text can be used to form a record identifier for an incoming message.
$e This pattern corresponds to the last wildcard portion of a subject as determined by the original subject in the subscription.
$t This pattern will be replaced by a time string of the form yyymmddhhmmssuuuuuu where uuuuuu is the number of microseconds adjusted to assure no duplicate values.
$(<key>) This patterns is replaced by what ever is in the message as described by the . An example is 'nats-$(id)'.
id_key Append generated record identifier to JSON using the value of this parameter as the key unless the value is an empty string.