Fake Mirrors
    Preparing search index...

    Class ConsumerRouter

    Represents the consumer router.

    Depends:

    import { DIContainer } from '@famir/common'
    import { ConsumerRouter } from '@famir/consumer'

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

    // Register in DI container
    ConsumerRouter.register(container)
    import { DIContainer } from '@famir/common'
    import { CONSUMER_ROUTER, type ConsumerRouter } from '@famir/consumer'
    import { ANALYZE_QUEUE_NAME } from '@famir/producer'

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

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

    // Add queue
    router.addQueue(ANALYZE_QUEUE_NAME)

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

    // Activate router
    router.activate()
    • Activates the router.

      Once activated, processors can be retrieved but not added.

      Returns void

    • 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.

    • Registers the router as a singleton in the DI container.

      Parameters

      • container: DIContainer

        The DI container to register in.

      Returns void