Also see the Javascript client documentation.
Publishes a new message to a stream. Requires a write permission to the stream.
{
"type": "publish",
"stream": "streamId",
"authKey": "authKey",
"msg": "{}", // the message as stringified json
"ts": 1533924184016, // timestamp (optional), defaults to current time on server
"pkey": "deviceId" // partition key (optional), defaults to none (random partition)
}
Requests that the client be subscribed to a stream-partition from the next published message. Will result in a subscribed
message, and a stream of broadcast
messages as they are published.
{
"type": "subscribe",
"stream": "streamId",
"partition": 0, // optional, defaults to 0
"authKey": "authKey" // optional, defaults to undefined
}
Field | Description |
---|---|
type | Always "subscribe" |
stream | Stream id to subscribe to |
partition | Partition number to subscribe to. Optional, defaults to 0 |
authKey | User API key or anonymous stream key. Optional. Public streams can be subscribed to without authentication. |
Unsubscribes the client from a stream-partition. The response message is unsubscribed
.
{
"type": "unsubscribe",
"stream": "id",
"partition": 0 // optional, defaults to 0
}
Field | Description |
---|---|
type | Always "unsubscribe" |
stream | Stream id to unsubscribe |
partition | Partition number to unsubscribe. Optional, defaults to 0 |
Requests a resend for a stream-partition. Responses are either a sequence of a resending
, one or more u
, and a resent
; or a no_resend
if there is nothing to resend.
{
"type": "resend",
"stream": "id",
"partition": 0 // optional, defaults to 0
"sub": "subId",
// one of: "resend_all": true, "resend_last": (number), "resend_from": (offset)
}
Field | Description |
---|---|
type | Always "unsubscribe" |
stream | Stream id to unsubscribe |
partition | Partition number to unsubscribe. Optional, defaults to 0 |
resend_all | Set to true to resend all messages in stream |
resend_last | Resend the latest N messages |
resend_from | Resend all messages from and including the given offset. Can be used in combination with resend_to |
resend_to | Resend up to given offset |
Messages sent by the server are arrays with the following structure:
[messageVersion, messageType, subId || "", messagePayload]
messageVersion
is 0 for all messages.messageType
identifies the message type as follows:
messageType | Description |
---|---|
0 | broadcast |
1 | unicast |
2 | subscribed |
3 | unsubscribed |
4 | resending |
5 | resent |
6 | no resend |
7 | error |
subId
is non-empty onunicast
messages and identifies the subscription by idmessagePayload
is the message payload as described below.
A message addressed to all subscriptions listening on the stream. The message payload is a an event in a stream, wrapped in a header array as follows:
[version (28), streamId, streamPartition, timestamp, ttl, offset, previousOffset, contentType, streamEvent]
version
is currently 28streamId
what stream this message belongs tostreamPartition
what stream partition this message belongs totimestamp
of the message (milliseconds format)ttl
time-to-live of the message in secondsoffset
is an increasing number that can be used for message ordering and gap detectionpreviousOffset
is theoffset
of the previous message, used for gap detectioncontentType
determines howstreamEvent
should be parsed:
contentType | Description |
---|---|
27 | streamEvent should be parsed as JSON |
Unicast messages have non-empty subId
. Content is just like in the broadcast message.
Sent in response to a subscribe
request. Lets the client know that streams were subscribed to.
{
"stream": "id",
"partition": 0
}
Sent in response to an unsubscribe
request.
{
"stream": "id",
"partition": 0
}
Sent in response to a resend
request. Informs the client that a resend is starting.
{
"stream": "id",
"partition": 0
}
Informs the client that a resend for a particular subscription subId
is complete.
{
"stream": "id",
"partition": 0
}
Sent in response to a resend
request. Informs the client that there was nothing to resend.
{
"stream": "id",
"partition": 0
}
Event | Arguments | Description |
---|---|---|
stream-object-created |
Stream | Emitted when a Stream reference object is created |
stream-object-deleted |
Stream | Emitted when a Stream reference object is deleted |