Subscribing to topics

Prerequisites
  • You must have a secure WebSocket connection to the switch.

  • Access to the switch REST API must be enabled. The REST API access mode can be either read-only or read/write.

Procedure
Using the WebSocket secure connection, send a subscribe message that contains the topics to which you want to subscribe and a poll interval hint, if any.

Some resource attributes—typically in the statistics category—are not populated until a client requests the information. The value of hint specifies how often—in seconds—the notification subsystem is to request information about the topics in the list.

For example:

{
  "type": "subscribe",
  "topics": [
    {
      "name": "/rest/v1/system/vrfs"
    },
    {
      "name": "/rest/v1/system/vlans/DEFAULT_VLAN_1?attributes=admin,oper_state_reason"
    }
  ],
  "hint": 5
}
  • If the subscriber already has a subscription to the specified topic, the following error is returned:

    {
      "type":"error",
      "message":"The topic or combination of topics have been already subscribed."
    }
  • If the URI in the topic name specifies a resource that is not in the configuration and state database, the following error is returned:

    {"type":"error","message":"Object not found."}
    

Example of a message returned by a successful subscription attempt:

{
  "type": "success",
  "subscriber_name": "4bcf8uka90ki",
  "subscription_name": "ns83n58dky",
  "data": [
    {
      "topicname": "/rest/v1/system/vlans/DEFAULT_VLAN_1?attributes=admin,oper_state_reason",
      "resources": [
        {
          "operation": "",
          "uri": "/rest/v1/system/vlans/DEFAULT_VLAN_1",
          "values": {
            "admin": "up",
            "oper_state_reason": "no_member_port"
          }
        }
      ]
    },
    {
      "topicname": "/rest/v1/system/vrfs",
      "resources": [
        {
          "operation": "",
          "uri": "/rest/v1/system/vrfs/default",
          "values": {}
        },
        {
          "operation": "",
          "uri": "/rest/v1/system/vrfs/mgmt",
          "values": {}
        }
      ]
    }
  ]
}