Skip to content

Commit

Permalink
docs(readme): add section for usage with custom provider
Browse files Browse the repository at this point in the history
  • Loading branch information
traoreak committed Mar 10, 2021
1 parent 9960243 commit 194f0ce
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default class AppModule {}

```

## Advanced usage
### Usage with nestjs-config

```ts
Expand Down Expand Up @@ -73,7 +74,24 @@ export default {
```
> Unfortunately multiple connections are unavailable when using the `forRootAsync` method.
## Connection Decorators
### Usage in custom provider
It is possible to inject the AmqpConnection in a factory of a custom provider if one needs such capability.


```ts
import { Connection as AmqpConnection } from 'amqplib';
import {ConfigService} from 'nestjs-config';
import {createConnectionToken} from 'nestjs-amqp/utils';

export const queueServiceProvider = {
provider: 'QueueService',
useFactory: (amqp: AmqpConnection, configService: ConfigService) => new QueueService(amqp, config.get('queue')),
inject: [createConnectionToken('default'), ConfigService],
}
```

It's also possible to give your connections names, if you have done so then use the name of your connection instead of ``default``.
### Connection Decorators

```ts
import {Module} from '@nestjs/common';
Expand Down

0 comments on commit 194f0ce

Please sign in to comment.