UNPKG

nodly

Version:

Nodly is an interactive CLI for scaffolding modern Node.js/Express.js backend projects with instant setup for databases, mailers, queues, sockets, and more. Skip boilerplate and start building features fast.

20 lines (17 loc) 545 B
import amqp from "amqplib"; let channel; export const connectRabbitMQ = async () => { try { const connection = await amqp.connect(process.env.RABBITMQ_URL || "amqp://localhost"); channel = await connection.createChannel(); console.log("RabbitMQ connected"); return channel; } catch (error) { console.error("RabbitMQ connection error:", error); throw error; } }; export const getRabbitChannel = () => { if (!channel) throw new Error("RabbitMQ not connected. Call connectRabbitMQ() first."); return channel; };