MessageStream
The MessageStream
class is a wrapper for MessagingService that handles routing and fragmentation according to the CSRP specification. A MessageStream object represents a single MessagingService topic.
Constructors
MessageStream new
MessageStream.new = function(topic: string?, bufferTimeout: number?): MessageStream
Returns a new MessageStream object. If topic
is not provided, "CSRP_GLOBAL"
will be used. If bufferTimeout
is not provided, 10 seconds will be used.
Arguments:
string?
topic
- The MessagingService topic to use.number?
bufferTimeout
- Timeout in seconds for fragment buffers.
Danger
Do not use a MessageStream or a MessagingService topic used by a MessageStream for sending or receiving messages that don't conform to the CSRP specification.
Properties
string Topic
The MessagingService topic used by the MessageStream.
Methods
void Send
MessageStream:Send = function(message: CsrpMessage)
Send a CsrpMessage to the MessageStream's topic. Automatically fragments the message if it exceeds the maximum message size. Retries sending the message if it fails up to 10 times with a 1 second delay between each attempt.
Arguments:
CsrpMessage
message
- The message to send.
StreamConnection Subscribe
MessageStream:Subscribe = function(callback: (CsrpMessage, number) -> ()): StreamConnection
Subscribe to the MessageStream. The callback will be invoked with the full message when all fragments of a message have been received. The callback will be invoked with two arguments: the CsrpMessage object and the time at which the last fragment of the message was received. The callback will only be invoked for messages that are intended for the current server.
Arguments:
(CsrpMessage, number) -> ()
callback
- The callback to invoke when a message is received.