subscribe capability for that channel.
Publishing is an operation available to the realtime and REST interfaces of Pub/Sub SDKs. REST publishing is more efficient if you don’t need to establish a persistent connection to Ably, such as to subscribe to messages. For example, if you have a server publishing messages to channels that doesn’t need to receive any updates from them.
Publish a message
Use thepublish() method to send messages to a channel.
Message name and data
When publishing a message, you provide two key pieces of information:- name: An event name that identifies the type of message. This is useful when you have different types of messages on the same channel.
- data: The message payload. This can be a string, JSON object, or binary data.
Publishing from REST
When you only need to publish messages and don’t need to subscribe to them, use the REST interface. This is more efficient as it doesn’t maintain a persistent connection:Batch publishing
You can publish multiple messages in a single API call for better performance:Publishing with extras
You can include additional metadata with your messages using theextras field:
Message acknowledgment
When using the realtime interface, you can provide a callback to know when the message has been successfully published:Publishing on behalf of others
Servers can publish messages on behalf of clients by specifying aclientId in the message:
Next steps
- Learn how to subscribe to messages
- Understand message format and metadata
- Explore message history
