Skip to content

subscribe Statement ​

The subscribe statement creates a subscription to a data stream.

Syntax ​

subscribe <stream_name>

Description ​

This statement establishes a subscription connection to a stream, routing all incoming data to the console. Each subscription receives a unique identifier for later management.

Parameters ​

  • stream_name: Name of the stream to subscribe to (must be a valid identifier)

Examples ​

Basic Subscription ​

subscribe sensor_data
subscribe events
subscribe logs

Multiple Subscriptions ​

subscribe temperature_stream
subscribe humidity_stream
subscribe pressure_stream

Behavior ​

  • Creates a subscription with a unique ID
  • Prints received data to the console in the format: 📡 [stream_name]: data
  • Subscription remains active until manually unsubscribed
  • Multiple subscriptions can be created to the same stream
  • Subscription ID is returned for later unsubscription

Output Format ​

When data is received, it's printed in this format:

📡 [sensor_data]: { "id": "sensor1", "temperature": 23.5, "timestamp": 1640995200 }
📡 [events]: { "type": "login", "user": "alice", "time": 1640995200 }