
Security News
minimatch Patches 3 High-Severity ReDoS Vulnerabilities
minimatch patched three high-severity ReDoS vulnerabilities that can stall the Node.js event loop, and Socket has released free certified patches.
Task and Message Queues with Multiple Providers
Messagepublish()subscribe()Task (Coming in v1.0.0)enqueue() (Coming in v1.0.0)dequeue() (Coming in v1.0.0)Acknowledge() in handler (Coming in v1.0.0)pnpm add qified
import { Qified, MemoryMessageProvider } from 'qified';
// Create a new Qified instance with a memory provider
const qified = new Qified({
messageProviders: new MemoryMessageProvider()
});
// Subscribe to a topic
await qified.subscribe('notifications', {
id: 'notificationHandler',
handler: async (message) => {
console.log('Received:', message.data);
}
});
// Publish a message
await qified.publish('notifications', {
id: 'msg-1',
data: { text: 'Hello, World!' }
});
// Clean up
await qified.disconnect();
new Qified(options?: QifiedOptions)
Options:
messageProviders?: MessageProvider | MessageProvider[] - a provider or Array of message providers to usetaskProviders?: TaskProvider[] - Array of task providers to useExample:
import { Qified, MemoryMessageProvider } from 'qified';
const qified = new Qified({
messageProviders: new MemoryMessageProvider()
});
messageProviders: MessageProvider[]Get or set the array of message providers. This property allows you to dynamically manage which message providers are active in your Qified instance.
Type: MessageProvider[]
Access: Read/Write
Description:
Use Cases:
Example:
import { Qified, MemoryMessageProvider } from 'qified';
import { NatsMessageProvider } from '@qified/nats';
import { RedisMessageProvider } from '@qified/redis';
const qified = new Qified({
messageProviders: new MemoryMessageProvider()
});
// Get current providers
const providers = qified.messageProviders;
console.log(`Currently using ${providers.length} provider(s)`);
// Add another provider
qified.messageProviders = [
new MemoryMessageProvider(),
new NatsMessageProvider()
];
// Replace all providers
qified.messageProviders = [
new RedisMessageProvider({ uri: 'redis://localhost:6379' })
];
// Access provider properties
qified.messageProviders.forEach(provider => {
console.log('Provider ID:', provider.id);
});
Important Notes:
disconnect() on old providers before replacing them to clean up resourcessubscribe, publish, unsubscribe) will execute across all providers in this arraySubscribe to a topic to receive messages. If multiple message providers are configured, this will subscribe on all of them.
Parameters:
topic: string - The topic to subscribe tohandler: TopicHandler - Object containing an optional id and a handler functionExample:
await qified.subscribe('user-events', {
id: 'userEventHandler',
handler: async (message) => {
console.log('User event:', message.data);
}
});
Publish a message to a topic. If multiple message providers are configured, this will publish to all of them.
Parameters:
topic: string - The topic to publish tomessage: Message - The message object to publishExample:
await qified.publish('user-events', {
id: 'evt-123',
data: {
userId: 'user-456',
action: 'login',
timestamp: Date.now()
},
headers: {
'content-type': 'application/json'
}
});
Unsubscribe from a topic. If an id is provided, only that handler is unsubscribed. Otherwise, all handlers for the topic are unsubscribed.
Parameters:
topic: string - The topic to unsubscribe fromid?: string - Optional handler ID. If not provided, all handlers are unsubscribedExample:
// Unsubscribe a specific handler
await qified.unsubscribe('user-events', 'userEventHandler');
// Unsubscribe all handlers for a topic
await qified.unsubscribe('user-events');
Disconnect from all providers and clean up resources.
Example:
await qified.disconnect();
Qified extends Hookified and emits events for all major operations. You can listen to these events to add custom logging, monitoring, or error handling.
The following events are available via the QifiedEvents enum:
QifiedEvents.publish - Emitted after a message is successfully publishedQifiedEvents.subscribe - Emitted after successfully subscribing to a topicQifiedEvents.unsubscribe - Emitted after successfully unsubscribing from a topicQifiedEvents.disconnect - Emitted after successfully disconnecting from all providersQifiedEvents.error - Emitted when an error occurs during any operationQifiedEvents.info - Emitted for informational messagesQifiedEvents.warn - Emitted for warning messagesUse the on() method to listen to events:
import { Qified, MemoryMessageProvider, QifiedEvents } from 'qified';
const qified = new Qified({
messageProviders: new MemoryMessageProvider()
});
// Listen for publish events
await qified.on(QifiedEvents.publish, async (data) => {
console.log('Message published to topic:', data.topic);
console.log('Message:', data.message);
});
// Listen for subscribe events
await qified.on(QifiedEvents.subscribe, async (data) => {
console.log('Subscribed to topic:', data.topic);
console.log('Handler ID:', data.handler.id);
});
// Listen for unsubscribe events
await qified.on(QifiedEvents.unsubscribe, async (data) => {
console.log('Unsubscribed from topic:', data.topic);
if (data.id) {
console.log('Handler ID:', data.id);
}
});
// Listen for disconnect events
await qified.on(QifiedEvents.disconnect, async () => {
console.log('Disconnected from all providers');
});
// Listen for errors
await qified.on(QifiedEvents.error, async (error) => {
console.error('Error occurred:', error);
});
// Now perform operations
await qified.subscribe('events', {
id: 'handler1',
handler: async (message) => {
console.log('Received:', message.data);
}
});
await qified.publish('events', {
id: 'msg-1',
data: { text: 'Hello!' }
});
await qified.unsubscribe('events', 'handler1');
await qified.disconnect();
Events provide a centralized way to handle errors across all operations:
import { Qified, QifiedEvents } from 'qified';
import { NatsMessageProvider } from '@qified/nats';
const qified = new Qified({
messageProviders: new NatsMessageProvider()
});
// Centralized error handler
await qified.on(QifiedEvents.error, async (error) => {
console.error('Qified error:', error.message);
// Send to error tracking service
// Log to file
// Send alert
});
// Errors from publish, subscribe, etc. will be caught and emitted
await qified.publish('topic', { id: '1', data: { test: true } });
There are multiple providers available to use:
qified library as MemoryMessageProvider.Qified is written in TypeScript and tests are written in vitest. To run the tests, use the following command:
pnpm install - This will install all the dependenciespnpm test:services:start - This will start the services needed for testing (Redis, RabbitMQ, etc)pnpm test - This will run the testsTo contribute follow the Contributing Guidelines and Code of Conduct.
FAQs
Task and Message Queues with Multiple Providers
The npm package qified receives a total of 3,595,606 weekly downloads. As such, qified popularity was classified as popular.
We found that qified demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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
minimatch patched three high-severity ReDoS vulnerabilities that can stall the Node.js event loop, and Socket has released free certified patches.

Research
/Security News
Socket uncovered 26 malicious npm packages tied to North Korea's Contagious Interview campaign, retrieving a live 9-module infostealer and RAT from the adversary's C2.

Research
An impersonated golang.org/x/crypto clone exfiltrates passwords, executes a remote shell stager, and delivers a Rekoobe backdoor on Linux.