This module provides a client for interacting with server-managed queues. It contains two primary exports:
Queue
– A simple class that represents a queue instance, holding its name and current size.QueuesClient
– A high-level client that sends requests through a provided RoomClient
to list, open, drain, close, send messages to, and receive messages from queues.Below is an example of how you might use the QueuesClient
in your code:
Queue
A basic representation of a queue, holding a name and its current size.
name: string
size: number
QueuesClient
The QueuesClient
is responsible for sending requests through a RoomClient
to perform various operations on queues.
room: RoomClient
RoomClient
, which handles the low-level communication with the server or service.list()
Queue
objects containing the name and size of each queue found on the server.open(name)
name
– The name of the queue to open.drain(name)
name
– The name of the queue to drain.close(name)
name
– The name of the queue to close.send(name, message, create)
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 to true
.create
is 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 to true
.wait
– (Optional) Whether to wait (block) until a message is available. Defaults to true
. Behavior may vary based on server-side configuration.Returns
A JSON-serializable object if a message is received, or null
if the queue was empty (represented by an EmptyResponse
).
Description
Tries to receive one message from the specified queue. If the response from the server is EmptyResponse
, the method returns null
. Otherwise, it returns the JSON object from the JsonResponse
.
Error Handling
When a request fails or the server returns an error response, the underlying RoomClient
may throw errors. Make sure to wrap calls in try/catch
if you need to handle them gracefully.
Concurrency and Performance
RoomClient
configuration is optimized for concurrency.receive
method’s wait
parameter may affect your application’s design. If wait
is true
, the call might block until a message is available (depending on the server’s capabilities).Extensibility
You can add additional queue-related functionality (e.g., message peek, dead-letter queues, etc.) by extending QueuesClient
or creating related classes that also use RoomClient
.
This module provides a client for interacting with server-managed queues. It contains two primary exports:
Queue
– A simple class that represents a queue instance, holding its name and current size.QueuesClient
– A high-level client that sends requests through a provided RoomClient
to list, open, drain, close, send messages to, and receive messages from queues.Below is an example of how you might use the QueuesClient
in your code:
Queue
A basic representation of a queue, holding a name and its current size.
name: string
size: number
QueuesClient
The QueuesClient
is responsible for sending requests through a RoomClient
to perform various operations on queues.
room: RoomClient
RoomClient
, which handles the low-level communication with the server or service.list()
Queue
objects containing the name and size of each queue found on the server.open(name)
name
– The name of the queue to open.drain(name)
name
– The name of the queue to drain.close(name)
name
– The name of the queue to close.send(name, message, create)
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 to true
.create
is 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 to true
.wait
– (Optional) Whether to wait (block) until a message is available. Defaults to true
. Behavior may vary based on server-side configuration.Returns
A JSON-serializable object if a message is received, or null
if the queue was empty (represented by an EmptyResponse
).
Description
Tries to receive one message from the specified queue. If the response from the server is EmptyResponse
, the method returns null
. Otherwise, it returns the JSON object from the JsonResponse
.
Error Handling
When a request fails or the server returns an error response, the underlying RoomClient
may throw errors. Make sure to wrap calls in try/catch
if you need to handle them gracefully.
Concurrency and Performance
RoomClient
configuration is optimized for concurrency.receive
method’s wait
parameter may affect your application’s design. If wait
is true
, the call might block until a message is available (depending on the server’s capabilities).Extensibility
You can add additional queue-related functionality (e.g., message peek, dead-letter queues, etc.) by extending QueuesClient
or creating related classes that also use RoomClient
.