Overview
TheQueuesClient lets you manage lightweight room-scoped queues for simple task/message passing:
- List queues with their current size.
- Open/create queues (or auto-create via
send/receivewhencreate=True). - Send messages, receive messages (optionally waiting), and drain/close queues.
API Methods
Below is an example of how you might use theQueuesClient in your code:
Queue
A basic representation of a queue, holding a name and its current size.
name: string
The name of the queue.size: number
The size (or length) of the queue at the time of retrieval.
QueuesClient
The QueuesClient is responsible for sending requests through a RoomClient to perform various operations on queues.
room: RoomClient
An instance ofRoomClient, which handles the low-level communication with the server or service.
list()
- Returns
An array ofQueueobjects containing the name and size of each queue found on the server.
open(name)
- Parameters:
name– The name of the queue to open.
- Description
Creates (or reopens) the queue if it is not present. If the queue already exists and is open, the server will reject a duplicate open request.
drain(name)
- Parameters:
name– The name of the queue to drain.
- Description
Removes all messages from the specified queue, effectively resetting its size to zero.
close(name)
- Parameters:
name– The name of the queue to close.
- Description
Closes the specified queue so that no further messages can be sent or received until it is reopened.
send(name, message, create)
- Parameters:
name– The name of the queue to send a message to.message– A JSON-serializable object containing the data you want to send.create– (Optional) Whether to create the queue if it does not exist. Defaults totrue.
- Description
Sends a message to the specified queue. Ifcreateis true, the queue will be created automatically if it doesn’t exist.
receive(name, create, wait)
-
Parameters:
name– The name of the queue to receive a message from.create– (Optional) Whether to create the queue if it does not exist. Defaults totrue.wait– (Optional) Whether to wait (block) until a message is available. Defaults totrue. Behavior may vary based on server-side configuration.
-
Returns
A JSON-serializable object if a message is received, ornullif the queue was empty (represented by anEmptyResponse). -
Description
Tries to receive one message from the specified queue. Withwait=True, the call blocks until a message arrives. Withwait=False, it returns immediately:nullif empty or the next message if available.
Additional Notes
-
Error Handling
When a request fails or the server returns an error response, the underlyingRoomClientmay throw errors. Make sure to wrap calls intry/catchif you need to handle them gracefully. -
Concurrency and Performance
- For high-throughput scenarios, ensure that your server and
RoomClientconfiguration is optimized for concurrency. - The
receivemethod’swaitparameter may affect your application’s design. Ifwaitistrue, the call might block until a message is available (depending on the server’s capabilities).
- For high-throughput scenarios, ensure that your server and
-
Extensibility
You can add additional queue-related functionality (e.g., message peek, dead-letter queues, etc.) by extendingQueuesClientor creating related classes that also useRoomClient. -
SDK availability
The server supportsqueues.open, but the Python SDK doesn’t expose anopenhelper today—queues are auto-created whencreate=Trueonsend/receive. JS/TS/Dart/.NET exposeopen.