Show TOC

Subscribe, Publish and Unsubscribe using JSON RequestsLocate this document in the navigation structure

In REST-like mode, use JSON requests to subscribe, publish, and unsubscribe to data in ESP projects.

Note This mode of the WebSocket Provider is deprecated and only available for backwards compatibility. SAP recommends using streaming mode instead.
See Streaming WebSocket Connections for additional information on using streaming mode for the WebSocket Provider.

For more information on subscriber and publisher options, see the Java SDK API reference located at STREAMING_HOME/doc/sdk/java/index.html.

The topic value in these requests can also use RESTful URLs. For example, http://localhost:9091/espws/restservice/workspaces/<workspace>/projects/<project>/streams/<window-or-stream>.

Note Use quotation marks for all values, other than integer and boolean, in a JSON request.
Subscribing
{
     "topic": "/<workspace>/<project>/<window-or-stream>",
     "messageType": "SUBSCRIBE",
     "subscribeOptions": {
          "gd": "<string>",
          "base": "<boolean>",
          "baseDrainTimeout": "<integer>",
          "droppable": "<boolean>",
          "lossy": "<boolean>",
          "pulseInterval": "<integer>",
          "queueSize": "<integer>",
          "shineThrough": "<boolean>",
          "preserveBlocks": "<boolean>"
     },
     "authorization": "Basic <auth-data>"
}

Subscribing with SQL

If no window or stream is specified for topic, subscription requests use SQL statements:

{
	"topic":"/<workspace>/<project>",
	"messageType":"SUBSCRIBE",
	"subscribeOptions": {
	},
	"sql":"<SQL-SELECT-statement>",
	"authorization":"Basic <auth-data>"
}
Note SQL subscription mode supports only SELECT statements. SELECT statements support FROM, WHERE, GROUP BY, and ORDER BY clauses.
Publishing
{
     "topic": "/<workspace>/<project>/<window-or-stream>",
     "event": {
          "count": "<integer>",
          "time": "<msdate>",
          "opCode": "<INSERT/UPDATE/DELETE/UPSERT/SAFEDELETE>",
          "value": [
          {
               "<column>": "<value>"
          },
          {
               "<column>": "<value>"
          }
          ]
     },
     "publishOptions": {
               "async": "<boolean>",
               "bufferSize": "<integer>",
     },
     "authorization": "Basic <auth-data>",
     "messageType": "PUBLISH"
}

The async publisher option is processed only for the first publish request; it is ignored in all subsequent publish calls.

The async option controls how the WebSocket Provider sends messages to the ESP project. If set to false, the WebSocket Provider waits for ESP to send an acknowledgment to each publish request. Regardless of the setting, all messages from the websocket client to the WebSocket Provider are asynchronous.

The bufferSize option controls how frequently the WebSocket Provider commits the published messages to the ESP project. This option is processed on every call, so you can change the commit frequency.

Unsubscribing
{
     "topic": "/<workspace>/<project>/<window-or-stream>",
     "messageType": "UNSUBSCRIBE",
     "authorization": "Basic <auth-data>"
}