3.0.3 • Published 4 months ago

adonis6-amqp v3.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

adonis6-amqp

npm-image license-image

Introduction

Typesafe AMQP provider for AdonisJS 6. Feel free to contribute or give suggestions.

Quick setup

Install the library

npm i adonis6-amqp
yarn add adonis6-amqp
pnpm add adonis6-amqp

Configure

node ace configure adonis6-amqp

Setup

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>
  }
}

Create a queue

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()

Validator

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(),
  })
)

Handler

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) { }
}

Send message to queue

Just import the queue you registered where you want to send a message.

import { yourQueue } from '#start/amqp'

// Typesafe
yourQueue.sendMessage({ randomString: 'test' })

License

Adonis6 AMQP is open-sourced software licensed under the MIT license.

3.0.3

4 months ago

3.0.2

4 months ago

3.0.1

4 months ago

3.0.0

4 months ago

2.0.3

4 months ago

2.0.2

4 months ago

2.0.5

4 months ago

2.0.4

4 months ago

2.0.1

4 months ago

2.0.0

4 months ago

1.0.3

5 months ago

1.0.2

5 months ago

1.0.1

5 months ago