Skip to content

Commit 6105c15

Browse files
Merge branch 'vahidvdn-vahidvdn/microservices-client-register-async-docs'
2 parents 0bd7775 + 4bdbb0e commit 6105c15

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

content/microservices/basics.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,20 +235,41 @@ One technique is to import the `ClientsModule`, which exposes the static `regist
235235

236236
The `name` property serves as an **injection token** that can be used to inject an instance of a `ClientProxy` where needed. The value of the `name` property, as an injection token, can be an arbitrary string or JavaScript symbol, as described [here](https://docs.nestjs.com/fundamentals/custom-providers#non-class-based-provider-tokens).
237237

238-
The `options` property is an object with the same properties we saw in the `createMicroservice()` method earlier.
238+
The `options` property is an object that contains the same properties we saw in the `createMicroservice()` method earlier.
239239

240240
```typescript
241241
@Module({
242242
imports: [
243243
ClientsModule.register([
244244
{ name: 'MATH_SERVICE', transport: Transport.TCP },
245245
]),
246-
]
247-
...
246+
],
247+
})
248+
```
249+
250+
Alternatively, you can use the `registerAsync()` method if you need to pass in configuration or perform any other asynchronous processes.
251+
252+
```typescript
253+
@Module({
254+
imports: [
255+
ClientsModule.registerAsync([
256+
{
257+
imports: [ConfigModule],
258+
name: 'MATH_SERVICE',
259+
useFactory: async (configService: ConfigService) => ({
260+
transport: Transport.TCP,
261+
options: {
262+
url: configService.get('URL'),
263+
},
264+
}),
265+
inject: [ConfigService],
266+
},
267+
]),
268+
],
248269
})
249270
```
250271

251-
Once the module has been imported, we can inject an instance of the `ClientProxy` configured as specified via the `'MATH_SERVICE'` transporter options shown above, using the `@Inject()` decorator.
272+
Once the module has been imported, you can inject an instance of the `ClientProxy` configured with the specified options for the `'MATH_SERVICE'` transporter using the `@Inject()` decorator.
252273

253274
```typescript
254275
constructor(

0 commit comments

Comments
 (0)