MessagingService
Allows servers of the same experience to communicate with each other.
Memory category | Instances |
---|
Member index 2
Description
MessagingService allows servers of the same experience to communicate with each other in real time (less than 1 second) using topics. Topics are developer‑defined strings (1–80 characters) that servers use to send and receive messages.
Delivery is best effort and not guaranteed. Make sure to architect your experience so delivery failures are not critical.
Cross-Server Messaging explores how to communicate between servers in greater detail.
If you want to publish ad-hoc messages to live game servers, you can use the Open Cloud APIs.
Limitations
Note that these limits are subject to change.
Limit | Maximum |
---|---|
Size of message | 1kB |
Messages sent per game server | 600 + 240 * (number of players in this game server) per minute |
Messages received per topic | (40 + 80 * number of servers) per minute |
Messages received for entire game | (400 + 200 * number of servers) per minute |
Subscriptions allowed per game server | 20 + 8 * (number of players in this game server) |
Subscribe requests per game server | 240 requests per minute |
History 6
- 573 Change ReturnType of PublishAsync from void to null
- 462 Change ThreadSafety of SubscribeAsync from to Unsafe
- 462 Change ThreadSafety of PublishAsync from to Unsafe
- 367 Add SubscribeAsync
- 367 Add PublishAsync
- 367 Add MessagingService
Members 2
PublishAsync
Parameters (2) | ||
---|---|---|
topic | string | |
Returns (1) | ||
null |
This function sends the provided message to all subscribers to the topic, triggering their registered callbacks to be invoked.
Yields until the message is received by the backend.
Thread safety | Unsafe |
---|
History 3
- 573 Change ReturnType of PublishAsync from void to null
- 462 Change ThreadSafety of PublishAsync from to Unsafe
- 367 Add PublishAsync
SubscribeAsync
Parameters (2) | ||
---|---|---|
topic | string | |
callback | Function | |
Returns (1) | ||
RBXScriptConnection |
This function registers a callback to begin listening to the given topic. The callback is invoked when a topic receives a message. It can be called multiple times for the same topic.
Callback
The callback is invoked with a single argument, a table with the following entries:
Field | Summary |
---|---|
Data | Developer supplied payload |
Sent | Unix time in seconds at which the message was sent |
It yields until the subscription is properly registered and returns a connection object.
To unsubscribe, call Disconnect() on the returned object. Once called, the callback should never be invoked. Killing the script containing the connections also causes the underlying connect to be unsubscribed.
See also MessagingService:PublishAsync() which sends the provided message to all subscribers to the topic, triggering their registered callbacks to be invoked.
Thread safety | Unsafe |
---|
History 2
- 462 Change ThreadSafety of SubscribeAsync from to Unsafe
- 367 Add SubscribeAsync