Skip to content

Solace messaging and subscription via RESTful API

The following page outlines an alternative method to interact with Solace using the the Solace REST API rather than via the C API. This may be suitable in low data rate settings.

REST publishing to Solace

In order to publish to a Solace broker via REST a kdb+ user should make use of the function .Q.hp to create a POST request.

Use the Solace documentation as a guide to configure HTTP parameters for your use case. Use it also to test the API before running from a kdb+ session

The following examples provide some basic commands to publish to queues and topics.

Publish to a queue

Publish the string 'hello world' to a Solace queue called KDB_QUEUE.

q).Q.hp["http://localhost:9000/QUEUE/KDB_QUEUE";.h.ty`text]"hello world"

Publish to a topic

Publish the string 'hello world' to a Solace topic called Q/topic via direct messaging.

q).Q.hp["http://localhost:9000/TOPIC/Q/test";.h.ty`text]"hello world"

REST Subscription

For a kdb+ instance to receive HTTP POST requests from Solace, configure .z.pp to receive these post requests.

You can then configure the Solace framework to publish to the kdb+ instance using the instance’s IP/port.

Remember to preface any Post Request Target with the character /.

The following example returns a HTTP 200 response on receipt of a message and prints out the received payload.

Configure the kdb+ instance as follows:

Start the instance on port 12341

q -p 12341

Define the .z.pp function to handle post requests

q).z.pp:{[x] 0N!((first where x[0]=" ")+1)_x[0];["200 OK";`txt;""];r}

Configuring a Solace REST Consumer using your host/port, with a queue binding will allow messages on the queue to be received in kdb+. (See Solace documentation on configuring REST consumers.)

It is possible to configure multiple REST endpoints in kdb+, with data transformations and callbacks.