Queues - Publish
Overview
Publishing to a queue submits background work for asynchronous processing.
In RelayX, queues are explicit resources. You must initialize a queue before you can publish jobs to it. Publishing does not implicitly create or infer queues. This makes queue usage predictable and prevents accidental job delivery to the wrong queue.
Publishing is fire-and-forget. A successful publish only confirms that the job was accepted by the RelayX backend. It does not mean the job has run or completed.
How This Works
Publishing a job follows a strict sequence:
- Create a RelayX client with API credentials.
- Initialize the client.
- Establish a network connection.
- Initialize the target queue.
- Publish jobs through the queue handle.
When publish() is called on a queue:
- The SDK validates the job payload.
- If the client is connected, the job is sent to the RelayX backend.
- The job becomes available to subscribed workers.
If the client is disconnected or reconnecting, the publish call returns False. A True return value only confirms backend acceptance, not execution.
API Usage
Client Initialization and Connection
from relayx_py import Realtime
import os
client = Realtime({
"api_key": os.getenv("RELAYX_API_KEY", None),
"secret": os.getenv("RELAYX_API_SECRET", None)
})
client.init()
await client.connect()
The client must be initialized and connected before any queue operations.
Initializing a Queue
Before publishing, explicitly initialize the queue.
worker_queue = await client.initQueue("<QUEUE_ID>")
<QUEUE_ID>uniquely identifies the queue.- The queue ID is found in the worker queue section of the developer console.
All publish and subscribe operations are performed through this queue instance.
Publishing a Job
success = await worker_queue.publish("email-jobs", {
"userId": "12345",
"template": "welcome-email",
})
if not success:
print("Job was not published")
Parameters
-
topic (
string, required)
Logical identifier for the job type. -
payload (
object, required)
Job data. RelayX treats this as opaque data. Validation is application-defined.
Return Value
True— job was accepted by the backend.False— job was not sent, usually because:- The client is disconnected or reconnecting.
- The connection has been closed.
A return value of True does not indicate job execution.
Failure & Edge Cases
Network Failures
If the connection drops:
publish()may returnFalse.- The job is not guaranteed to be persisted.
- Retry after reconnection if the job is important.
Invalid Input
publish() throws an error if:
- The topic name is invalid.
- The topic is a system-reserved topic.
- The client doesn't have permissions to publish to the specified topic. More information here
- Publish attempt is made when allowed message quota (hard limit with no extra messages) has exceeded.
These errors must be caught by the application.
Process Crashes
- If the process crashes after
publish()returnsTrue, the job remains queued. - If it crashes before a successful return, the job may be lost.
Common Mistakes
Skipping Queue Initialization
Calling publish() without first calling initQueue() will fail. Queue initialization is mandatory.
Assuming Publish Waits for Processing
Publishing does not wait for a worker to run the job. It only confirms backend acceptance.
Assuming Exactly-Once Execution
Jobs are delivered at least once. Workers must be idempotent.
Notes & Limitations
- An active connection is required to publish.
- Publishing does not depend on worker availability.
- RelayX does not support delayed or scheduled jobs.
Join our Discord server, post your concern & someone from our team will help you out ✌️