Fake Mirrors
    Preparing search index...

    Class ConsumerRouter

    Represents the consumer router.

    Depends:

    import { DIContainer } from '@famir/common'
    import { CONSUMER_ROUTER, ConsumerRouter } from '@famir/consumer'
    import { ANALYZE_QUEUE_NAME } from '@famir/producer'

    // Get container singleton
    const container = DIContainer.getInstance()

    // Register in DI container
    ConsumerRouter.register(container)

    // Resolve from DI container
    const router = container.resolve<ConsumerRouter>(CONSUMER_ROUTER)

    // Add queue
    router.addQueue()

    // Add custom processor
    router.addProcessor(ANALYZE_QUEUE_NAME, async (data) => {
    // Worker logic here..
    console.log(data)

    return true
    })

    // Activate router
    router.activate()
    • Adds a queue in the router.

      Queues can only be added before the router is activated.

      Parameters

      • queueName: string

        The name of the queue.

      Returns this

      This router for method chaining.

      Error If the router is already active.

      Error If the queue is already exist.

    • Retrieves a processor for a specific queue and job.

      Processors can only be retrieved after the router is activated.

      Parameters

      • queueName: string

        The name of the queue.

      • jobName: string

        The name of the job.

      Returns ConsumerProcessor<unknown> | undefined

      The processor function, or undefined if not found.

      Error If the router is not active.