Ephemeral queues live in memory, outside the log, for request/reply. The worker answers on whatever inbox a request names; the caller makes a private inbox and waits on it. There is no transaction or replay here, and a crash loses what is in flight.
The worker:
const { messages } = await queen.ephemeral.pop('price-requests', { group: 'pricers', wait: true })
for (const m of messages) {
await queen.ephemeral.push(m.payload.replyTo, [{ sku: m.payload.sku, price: 59.9 }])
}
await queen.ephemeral.ack('price-requests', messages, { group: 'pricers' })result = await queen.ephemeral.pop("price-requests", group="pricers", wait=True)
for m in result["messages"]:
await queen.ephemeral.push(m["payload"]["replyTo"], [{"sku": m["payload"]["sku"], "price": 59.9}])
await queen.ephemeral.ack("price-requests", result["messages"], group="pricers")batch, err := client.Ephemeral().Pop(ctx, "price-requests",
queen.EphemeralPopOptions{Group: "pricers", Wait: true})
if err != nil {
log.Fatal(err)
}
for _, m := range batch.Messages {
var req struct{ Sku, ReplyTo string }
_ = json.Unmarshal(m.Payload, &req)
_, _ = client.Ephemeral().Push(ctx, req.ReplyTo,
[]map[string]interface{}{{"sku": req.Sku, "price": 59.9}})
}
_, _ = client.Ephemeral().Ack(ctx, "price-requests", batch.Messages,
queen.EphemeralAckOptions{Group: "pricers"})let eph = queen.ephemeral();
let batch = eph.pop("price-requests").group("pricers").wait(true).send().await?;
for m in &batch.messages {
let reply_to = m.payload["replyTo"].as_str().unwrap_or_default();
eph.push(reply_to, json!({ "sku": m.payload["sku"], "price": 59.9 })).send().await?;
}
eph.ack(&batch).await?;$result = $queen->ephemeral()->pop('price-requests', ['group' => 'pricers', 'wait' => true]);
foreach ($result['messages'] as $m) {
$queen->ephemeral()->push($m['payload']['replyTo'], [['sku' => $m['payload']['sku'], 'price' => 59.9]]);
}
$queen->ephemeral()->ack('price-requests', $result['messages'], ['group' => 'pricers']);queen::EphemeralPopOptions take;
take.group = "pricers";
take.wait = true;
json batch = client.ephemeral().pop("price-requests", take);
for (const json& m : batch["messages"]) {
json answer = {{"sku", m["payload"]["sku"]}, {"price", 59.9}};
client.ephemeral().push(m["payload"]["replyTo"], json::array({answer}));
}
queen::EphemeralAckOptions done;
done.group = "pricers";
client.ephemeral().ack("price-requests", batch["messages"], done);The caller:
const inbox = `inbox-${crypto.randomUUID()}` // a private reply queue
await queen.ephemeral.push('price-requests', [{ sku: 'A-1', replyTo: inbox }])
const reply = await queen.ephemeral.pop(inbox, { wait: true, timeout: 5000, commitOnDelivery: true })
console.log(reply.messages[0]?.payload) // { sku: 'A-1', price: 59.9 }inbox = f"inbox-{uuid.uuid4()}" # a private reply queue
await queen.ephemeral.push("price-requests", [{"sku": "A-1", "replyTo": inbox}])
reply = await queen.ephemeral.pop(inbox, wait=True, timeout=5000, commit_on_delivery=True)
print(reply["messages"][0]["payload"]) # {'sku': 'A-1', 'price': 59.9}inbox := "inbox-" + queen.GenerateUUID() // a private reply queue
_, err = client.Ephemeral().Push(ctx, "price-requests",
[]map[string]interface{}{{"sku": "A-1", "replyTo": inbox}})
if err != nil {
log.Fatal(err)
}
reply, err := client.Ephemeral().Pop(ctx, inbox,
queen.EphemeralPopOptions{Wait: true, TimeoutMillis: 5000, CommitOnDelivery: true})
if err != nil {
log.Fatal(err)
}
fmt.Println(string(reply.Messages[0].Payload)) // {"price":59.9,"sku":"A-1"}let eph = queen.ephemeral();
let inbox = format!("inbox-{}", queen_mq::uuid::uuidv7()); // a private reply queue
eph.push("price-requests", json!({ "sku": "A-1", "replyTo": inbox })).send().await?;
let reply = eph.pop(&inbox).wait(true).poll_timeout(Duration::from_secs(5))
.commit_on_delivery(true).send().await?;
println!("{}", reply.messages[0].payload); // {"price":59.9,"sku":"A-1"}$inbox = 'inbox-' . bin2hex(random_bytes(8)); // a private reply queue
$queen->ephemeral()->push('price-requests', [['sku' => 'A-1', 'replyTo' => $inbox]]);
$reply = $queen->ephemeral()->pop($inbox, ['wait' => true, 'timeout' => 5000, 'commitOnDelivery' => true]);
print_r($reply['messages'][0]['payload']); // [sku => A-1, price => 59.9]auto inbox = "inbox-" + queen::util::generate_uuid_v7(); // a private reply queue
json request = {{"sku", "A-1"}, {"replyTo", inbox}};
client.ephemeral().push("price-requests", json::array({request}));
queen::EphemeralPopOptions reply_wait;
reply_wait.wait = true;
reply_wait.timeout_millis = 5000;
reply_wait.commit_on_delivery = true;
json reply = client.ephemeral().pop(inbox, reply_wait);
std::cout << reply["messages"][0]["payload"] << "\n"; // {"price":59.9,"sku":"A-1"}Why
a request that waits for an answer (“what is the price of A-1, now?”) needs speed more than history. Writing it to disk, replicating it and keeping it for days would cost time for nothing. Ephemeral queues keep the same groups, leases and acks, and skip the log. Use a regular queue for anything that must survive a crash.
See also
- Request and reply: a quote with a timeout and a fallback.
- HTTP API: the
/api/v1/ephemeralendpoints.