# Producers

## Producers

Job producers add jobs to queues. Producers are typically application services (Nest providers). To add jobs to a queue, first inject the queue into the service as follows:

```typescript
import { Injectable } from '@nestjs/common';
import { QueuePro } from 'taskforcesh/bullmq-pro';
import { InjectQueue } from '@taskforcesh/nestjs-bullmq-pro';

@Injectable()
export class AudioService {
  constructor(@InjectQueue('audio') private audioQueue: QueuePro) {}
}
```

{% hint style="info" %}
The `@InjectQueue()` decorator identifies the queue by its name, as provided in the `registerQueue()`.
{% endhint %}

Now, add a job by calling the queue's `add()` method.

```typescript
const job = await this.audioQueue.add({
  foo: 'bar',
});
```

## Flow Producers

To add flows, first inject the flow producer into the service as follows:

```typescript
import { Injectable } from '@nestjs/common';
import { FlowProducerPro } from 'taskforcesh/bullmq-pro';
import { InjectFlowProducer } from '@taskforcesh/nestjs-bullmq-pro';

@Injectable()
export class FlowService {
  constructor(
    @InjectFlowProducer('flow') private fooFlowProducer: FlowProducerPro,
  ) {}
}
```

{% hint style="info" %}
The `@InjectFlowProducer()` decorator identifies the flow producer by its name, as provided in the `registerFlowProducer()`.
{% endhint %}

Now, add a flow by calling the flow producer's `add()` method.

```typescript
const job = await this.fooFlowProducer.add({
  name: 'root-job',
  queueName: 'topQueueName',
  data: {},
  children: [
    {
      name,
      data: { idx: 0, foo: 'bar' },
      queueName: 'childrenQueueName',
    },
  ],
});
```

### Read more:

* 💡 [Queues Technique](https://docs.nestjs.com/techniques/queues)
* 💡 [Inject Queue API Reference](https://nestjs.bullmq.pro/functions/InjectQueue.html)
* 💡 [Inject Flow Producer API Reference](https://nestjs.bullmq.pro/functions/InjectFlowProducer.html)
* 💡 [QueuePro API Reference](https://api.bullmq.pro/classes/v7.QueuePro.html)
* 💡 [FlowProducerPro API Reference](https://api.bullmq.pro/classes/v7.FlowProducerPro.html)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.bullmq.io/bullmq-pro/nestjs/producers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
