
Product
Introducing Pull Request Stories to Help Security Teams Track Supply Chain Risks
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
@apogeelabs/hoppity-delayed-publish
Advanced tools
A hoppity extension that provides delayed publish functionality for RabbitMQ messaging using TTL (Time-To-Live) and dead letter exchanges.
npm install @apogeelabs/hoppity-delayed-publish
import hoppity from "@apogeelabs/hoppity";
import { withDelayedPublish } from "@apogeelabs/hoppity-delayed-publish";
import { randomUUID } from "crypto";
// Create broker with delayed publish support
const broker = await hoppity
.withTopology(baseTopology)
.use(
withDelayedPublish({
serviceName: "my-service",
instanceId: randomUUID(),
defaultDelay: 30000, // 30 seconds
})
)
.build();
// Publish a message with a delay
await broker.delayedPublish(
"my-exchange-publication",
{ message: "This will be published in 5 seconds" },
undefined, // optional publication overrides
5000 // 5 seconds delay
);
withDelayedPublish(options)
Middleware function that adds delayed publish capabilities to your hoppity broker.
serviceName
(required): The name of the service (used for queue naming)instanceId
(required): Unique instance identifier (used for queue naming)defaultDelay
(optional): Default delay in milliseconds when no delay is specified (default: 30000)logger
(optional): Logger instance for delayed publish operationsbroker.delayedPublish(publication, message, overrides?, delay?)
Publishes a message with a delay before it gets re-published to the original destination.
publication
(string): The original publication name to use when re-publishingmessage
(any): The message to publishoverrides
(optional): Publication configuration overridesdelay
(optional): Delay in milliseconds (uses defaultDelay if not specified)Promise that resolves when the message is published to the wait queue.
The delayed publish functionality uses RabbitMQ's TTL (Time-To-Live) feature with dead letter exchanges:
The middleware automatically adds the following infrastructure to your topology:
// Base topology (minimal example)
const baseTopology = {
vhosts: {
"/": {
connection: {
hostname: "localhost",
port: 5672,
user: "guest",
password: "guest",
},
},
},
};
// After applying withDelayedPublish({ serviceName: "my-service", instanceId: "instance-1" })
// The topology becomes:
const modifiedTopology = {
vhosts: {
"/": {
connection: {
hostname: "localhost",
port: 5672,
user: "guest",
password: "guest",
},
queues: {
"my-service_wait": {
options: {
durable: false,
autoDelete: false,
arguments: {
"x-dead-letter-exchange": "", // Default direct exchange
"x-dead-letter-routing-key": "my-service_ready",
},
},
},
"my-service_ready": {
options: {
durable: false,
autoDelete: false,
},
},
"my-service_delayed_errors": {
options: {
durable: false,
autoDelete: false,
},
},
},
publications: {
"my-service_delayed_wait": {
exchange: "", // Default direct exchange
routingKey: "my-service_wait",
options: {
persistent: false,
},
},
},
subscriptions: {
"my-service_ready_subscription": {
queue: "my-service_ready",
options: {
prefetch: 1,
},
},
},
},
},
};
Queue Descriptions:
{serviceName}_wait
: Temporary queue where delayed messages are stored with TTL{serviceName}_ready
: Queue that receives expired messages from the wait queue{serviceName}_delayed_errors
: Queue for messages that exceed retry limitsPublications:
{serviceName}_delayed_wait
: Publication for sending messages to the wait queueSubscriptions:
{serviceName}_ready_subscription
: Subscription that processes expired messages and re-publishes themThe package provides structured error handling with specific error codes:
QUEUE_FULL
: Wait queue is fullREPUBLISH_FAILED
: Failed to re-publish messageMAX_RETRIES_EXCEEDED
: Maximum retry attempts exceededINVALID_DELAY
: Invalid delay value (must be > 0)See the examples/delayed-publish/
directory for complete working examples demonstrating delayed publish functionality.
This package depends on:
@apogeelabs/hoppity
- The core hoppity libraryrascal
- The underlying RabbitMQ librarylodash
- For utility functionsISC
FAQs
Delayed publish functionality for hoppity
We found that @apogeelabs/hoppity-delayed-publish demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
Research
/Security News
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.