Skip to content

Get Started with Kyo͞o

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

Prerequisites

  • Node.js version 22 or higher.
  • An AMQP, Redis or SQS Queue Broker.

Installation

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

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

Initialize the Connection

Create a connection to your preferred queue broker.

typescript
import { KyooConnection } from "@nhtio/kyoo";

const kyoo = new KyooConnection({
    client: '...',
    configuration: {
        // ...
    }
})

kyoo.connect().then((connected) => {
    // ...
})

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.