Skip to content

Quickstart

Getting started with Adonis Kyo͞o is quick and easy. Just follow the steps below and you'll be up and running in no time.

Installation

You can install @nhtio/adonis-kyoo directly from your preferred package manager

sh
npm i @nhtio/adonis-kyoo
sh
pnpm add @nhtio/adonis-kyoo
sh
yarn add @nhtio/adonis-kyoo

Configuration

Use the Adonis built-in configuration utility to automatically create the relevant configuration files:

shell
node ace configure @nhtio/adonis-kyoo

It will create the file config/kyoo.ts with the following content:

typescript
import env from '#start/env'
import { defineConfig, definePotentialConfigFromEnv } from '@nhtio/adonis-kyoo/config'

const potential = definePotentialConfigFromEnv({
    KYOO_CLIENT: env.get('KYOO_CLIENT'),
    KYOO_REDIS_HOST: env.get('KYOO_REDIS_HOST', '127.0.0.1'),
    KYOO_REDIS_PORT: env.get('KYOO_REDIS_PORT', 6379),
    KYOO_REDIS_PASSWORD: env.get('KYOO_REDIS_PASSWORD'),
    KYOO_REDIS_DB: env.get('KYOO_REDIS_DB', 0),
    KYOO_REDIS_TLS: env.get('KYOO_REDIS_TLS', false),
    KYOO_AMQP_PROTOCOL: env.get('KYOO_AMQP_PROTOCOL', 'amqp'),
    KYOO_AMQP_HOSTNAME: env.get('KYOO_AMQP_HOSTNAME', '127.0.0.1'),
    KYOO_AMQP_PORT: env.get('KYOO_AMQP_PORT', 5672),
    KYOO_AMQP_USERNAME: env.get('KYOO_AMQP_USERNAME', 'guest'),
    KYOO_AMQP_PASSWORD: env.get('KYOO_AMQP_PASSWORD', 'guest'),
    KYOO_AMQP_VHOST: env.get('KYOO_AMQP_VHOST', '/'),
    KYOO_AMQP_EXCHANGE: env.get('KYOO_AMQP_EXCHANGE', 'kyoo'),
    KYOO_AMQP_NAME: env.get('KYOO_AMQP_NAME'),
    KYOO_AMQP_FRAMEMAX: env.get('KYOO_AMQP_FRAMEMAX'),
    KYOO_AMQP_CHANNELMAX: env.get('KYOO_AMQP_CHANNELMAX'),
    KYOO_AMQP_HEARTBEAT: env.get('KYOO_AMQP_HEARTBEAT'),
    KYOO_SQS_ENDPOINT: env.get('KYOO_SQS_ENDPOINT'),
    KYOO_SQS_REGION: env.get('KYOO_SQS_REGION'),
    KYOO_SQS_ACCESS_KEY_ID: env.get('KYOO_SQS_ACCESS_KEY_ID'),
    KYOO_SQS_SECRET_ACCESS_KEY: env.get('KYOO_SQS_SECRET_ACCESS_KEY'),
})

export default defineConfig(potential);

This content is designed to allow you to utilize environmental variables for configuring the Adonis Kyo͞o Connection, however you can change this to directly create a configuration for Kyo͞o using the defineConfig method.

Accessing the Adonis Kyo͞o Connection

You can access the Adonis Kyo͞o Connection using one of the following methods:

1. As an importable service

typescript
import kyoo from '@nhtio/adonis-kyoo/services/main'
typescript
import { main as kyoo } from '@nhtio/adonis-kyoo/services'

2. As an Attribute of the Application

typescript
import { default as app } from "@adonisjs/core/services/app";

app.kyoo // the Adonis Kyo͞o Connection is accessible as `app.kyoo`

3. Using Container Services

typescript
import { default as app } from "@adonisjs/core/services/app";

// Resolve the Adonis Kyo͞o Connection from the IoC container
const kyoo = await app.container.make('kyoo');

For more information about KyooConnection see the KyooConnection API Documentation.

Initialize a Queue

Once you have a connection, create a queue to get started.

typescript
const queue = kyoo.queues.get('...');

For more information about KyooQueue see the KyooQueue API Documentation.

Add Jobs

Add jobs to your queue to be processed later by a worker.

typescript
queue.jobs.enqueue({
    payload: {
        // ...
    }
}).then((enqueued: boolean) => {
    // ...
})

queue.jobs.enqueue({
    payload: {
        // ...
    }
}, {
    payload: {
        // ...
    }
}, {
    payload: {
        // ...
    }
}, {
    payload: {
        // ...
    }
}).then((enqueued: boolean[]) => {
    // ...
})

For more information about the options for enqueuing a job see the KyooJobToEnqueue API Documentation.

Process Jobs

Setup a worker to process jobs according to your own logic.

typescript
const worker = queue.worker(async ({job}, {ack, nack}) => {
    // ...
}, {
    autoStart: false,
    blocking: true,
})

For more information about creating a worker, see the KyooQueue.worker() API Documentation.