How to Subscribe to an Event Using STOMP

These instructions detail how to subscribe to an event generated by a Virtual Device in Iotellect using Postman and the STOMP API. The Iotellect server in this example is available on localhost and the target Virtual Device is users.admin.devices.virtual1. Crucially, messages sent via STOMP must adhere to a strict format and end with the hexadecimal sequence 0D 0A 0D 0A 00.

Instructions

  1. Acquire an Authentication Token:

  • Endpoint: http://localhost:8080/rest/auth

  • Method: POST

  • Body (JSON):

    {
       "username":"admin",
       "password":"admin"
    }
  • Response (JSON): You will receive a JSON object containing an authentication token.

    {
       "token": "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI4N2VhNjc4OS00MmFjLTQ4YzMtOGYwZS00YmU5YWE2MjU4MGEiLCJzdWIiOiJhZG1pbiIsImF1ZCI6ImFjY2VzcyIsImlhdCI6MTcyNTUyMjA3MSwiZXhwIjoxNzI1NTI1NjcxfQ.tOkBhfyPeKhoeNpsAXQMIsRDcz-bUafP42_k79E2_JE"
    }
  1. Configure Postman for STOMP Connections:

  • URL: wss://localhost:8443/rest/v1/stomp

  • Headers:

    • Key: Authorization

    • Value: Bearer <token> (Replace <token> with the token received in step 1).

  1. Establish the STOMP Connection:

  • Click the "Connect" button in Postman.

  1. Send the CONNECT Frame:

  • Message Format: Text

  • Message Body:

    CONNECT
    Authorization:<token>

    (Replace <token> with the token from step 1. Note: There should be no "Bearer" prefix here).

  • Click the "Send" button.

  1. Send the Frame Terminator:

  • Message Format: Binary, Hexadecimal

  • Message Body: 0D 0A 0D 0A 00

  • Click the "Send" button.

  1. Send the SUBSCRIBE Frame:

  • Message Format: Text

  • Message Body:

    SUBSCRIBE
    id:0
    destination:/v1/contexts/users.admin.devices.virtual1/events/event1
  • Click the "Send" button.

  1. Send the Frame Terminator (Again):

  • Message Format: Binary, Hexadecimal

  • Message Body: 0D 0A 0D 0A 00

  • Click the "Send" button.

  1. Generate an Event in Iotellect:

  • Using the Iotellect interface, generate an event of Type 1 for the Virtual Device "users.admin.devices.virtual1".

  1. Receive the Event in Postman:

  • Postman will receive a MESSAGE frame containing the event data in JSON format. The frame will include headers like destination, content-type, subscription, message-id, and content-length, followed by the event data itself.

By following these steps, you can successfully leverage Postman and STOMP to subscribe to Iotellect events and gain real-time insights into your system's data via API.

Was this page helpful?