
Security News
Software Engineering Daily Podcast: Feross on AI, Open Source, and Supply Chain Risk
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.
simple-queue-decorator
Advanced tools
by @foundernest
Simple decorator-based wrapper for easy RabbitMQ queuing.
Both JavaScript and Typescript can be used, however, this library takes advantage of Typescript decorators. OnQueue decorator is only available using Typescript.
A running instance of RabbitMQ is needed, a docker-compose file is provided to use along with this library in a dev env (
docker-compose up -d rabbitmq). Do not use the given image in production
Init the service:
import * as SimpleQueueDecorator from 'simple-queue-decorator'
await SimpleQueueDecorator.init({
url: "127.0.0.1",
user: "guest",
password: "guest"
})
await SimpleQueueDecorator.close(); // Closes the service
Consume Messages (this can be done before init):
import { OnQueue } from 'simple-queue-decorator'
class MyConsumer {
@OnQueue('my-queue')
public static async onMessageReceived(msg: any) {
console.log("Message Received", msg.foo)
await doSomethingWithMyMsg(msg) // If this returns a rejected promise, message will be re-queued once
}
}
It is recommended to use static methods with queue decorator
Send Messages (Service must be initiated beforehand):
import * as SimpleQueueDecorator from 'simple-queue-decorator'
SimpleQueueDecorator.sendMessage('my-queue', {foo: "my message name"})
Messages can also be listened without using the decorator:
import * as SimpleQueueDecorator from 'simple-queue-decorator'
SimpleQueueDecorator.registerQueue("my-queue", async (msg) => {
console.log("Message Received", msg.foo)
await doSomethingWithMyMsg(msg)
})
This is preferable if using JavaScript or using dynamic dependencies (e.g. injectables) in the queue callback. RegisterQueue also support an array of queues, the callback will be execute for any message in any of those queues.
Send a message with priority:
import * as SimpleQueueDecorator from 'simple-queue-decorator'
SimpleQueueDecorator.sendMessage('my-queue',
{foo: "my message name"},
{
priority: SimpleQueueDecorator.MessagePriority.HIGH
});
Messages will be ordered and received according to priority. Priority can be LOW, MEDIUM or HIGH, a number ranging from 1 to 10 can also be used. Keep in mind the following:
LOW)The following options can be passed to init:
init, if 0, it will attempt indefinitely. Defaults to 0.node and npm required, either docker or a running instance of rabbitmq required.
npm installnpm run tsc to compiledocker-compose up -d rabbitmq to launch rabbitmqnpm test to compile and execute tests (rabbitmq must be running)This library makes several assumptions on how the messages are going to be consumed, as such, if your needs are different, we recommend directly using amqplib.
FAQs
A simple interface with RabbitMQ through typescript decorators
The npm package simple-queue-decorator receives a total of 11 weekly downloads. As such, simple-queue-decorator popularity was classified as not popular.
We found that simple-queue-decorator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 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.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.

Security News
GitHub has revoked npm classic tokens for publishing; maintainers must migrate, but OpenJS warns OIDC trusted publishing still has risky gaps for critical projects.

Security News
Rust’s crates.io team is advancing an RFC to add a Security tab that surfaces RustSec vulnerability and unsoundness advisories directly on crate pages.