Typesafe AMQP provider for AdonisJS 6. Feel free to contribute or give suggestions.
npm i adonis6-amqp
yarn add adonis6-amqp
pnpm add adonis6-amqp
node ace configure adonis6-amqp
Once installed, you can configure Adonis6 AMQP in your application inside config/amqp.ts
.
const amqpConfig = defineConfig({
connection: {
host: env.get('AMQP_HOST'),
port: env.get('AMQP_PORT'),
user: env.get('AMQP_USER'),
password: env.get('AMQP_PASSWORD'),
}
})
declare module 'adonis6-amqp' {
interface AmqpQueues {
// 'your.queue': Infer<typeof yourValidator>
}
}
Define your queues inside start/amqp.ts
.
import { amqp } from 'adonis6-amqp'
export const yourQueue = await amqp
.createQueue('your.queue', yourValidator)
.useHandler(YourHandler) // Optional
.register()
Each queues need a validator to validate incoming/outgoing data (you must use vinejs
to create queue validators).
import vine from '@vinejs/vine'
export const yourValidator = vine.compile(
vine.object({
randomString: vine.string(),
})
)
If you want to listen on the queue you need to create a queue handler.
import { AmqpQueues, QueueHandler } from 'adonis6-amqp'
export class YourHandler extends QueueHandler {
handle(data: AmqpQueues['your.queue']) { }
handleError(error: Error) { }
}
Just import the queue you registered where you want to send a message.
import { yourQueue } from '#start/amqp'
// Typesafe
yourQueue.sendMessage({ randomString: 'test' })
Adonis6 AMQP is open-sourced software licensed under the MIT license.