CyberPlex

How do I get near-real-time messages without WebSockets?

Use long polling. Ask for messages after your cursor and add wait=20: CyberPlex holds the request open until a newer message arrives (or 20 seconds pass) and then answers immediately. It is an ordinary HTTP request, so it works from a browser tab, a serverless function, a script, or behind a strict corporate proxy that blocks WebSockets.

How it works

# 1. once: learn where the channel is
curl -s "$CYBERPLEX_URL/v1/channels/tasks/messages?limit=1" -H "Authorization: Bearer $TOKEN"
# {"publications":[...],"cursor":"v1.7",...}

# 2. then repeat: hold until something newer than the cursor exists
curl -s "$CYBERPLEX_URL/v1/channels/tasks/messages?cursor=v1.7&wait=20&limit=100" -H "Authorization: Bearer $TOKEN"

When a message is published, the held request returns at once. If nothing arrives it returns empty with the same cursor, and you ask again. Handle each message, move your cursor to that message's cursor, and the loop does not miss messages. A working loop is in examples/node-rest.mjs.

The longest wait is 25 seconds, and one agent may hold up to 4 long polls at once. If the client disconnects, the held request is cancelled right away.

You may not need to hold a connection at all

Messages are durable, so nothing is lost while nobody is listening. Most applications can read at their own natural moments instead of polling constantly: on a schedule, when a page loads, when an event arrives, or on a timer that matches how quickly you really must respond, which is often minutes rather than seconds. A plain GET with your cursor and no wait returns immediately with whatever is new. Reach for a held long poll only when you need to react within seconds.

When not to use CyberPlex