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.
Some resource attributes—typically in the statistics category—are not populated until a client requests the information.
For example:
If there is an error in the syntax of the subscribe message, an error message is sent back to the client with the description of the error. For example, for the following incorrect subscribe message:
…{“主题”:[{“名称”:“/ rest / v10.04/system/vrfssss"}],"type":"subscribe"} ...
The corresponding error message is sent:
{ "type":"error", "message": "resource or attribute vrfssss not found", "data": null }
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." }
Example of a message returned by a successful subscription attempt:
{ "type": "success", "data": [ { "topicname": "/rest/v10.04/system/vlans/1?attributes=admin,oper_state_reason", "resources": [ { "operation": "", "uri": "/rest/v10.04/system/vlans/1", "values": { "admin": "up", "oper_state_reason": "no_member_port" } } ] }, { "topicname": "/rest/v10.04/system/vrfs", "resources": [ { "operation": "", "uri": "/rest/v10.04/system/vrfs/default", "values": {} }, { "operation": "", "uri": "/rest/v10.04/system/vrfs/mgmt", "values": {} } ] } ], "subscriber_name": "4bcf8uka90ki", }