Skip to content

Commit 0bcb898

Browse files
docs(microservices): add mention of rxjs when using interceptors
1 parent 70f5d2e commit 0bcb898

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

content/microservices/custom-transport.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,22 @@ Hello world!
103103

104104
Which means that our method handler was properly executed.
105105

106+
When using a `CustomTransportStrategy` with [Interceptors](/interceptors) the handlers are wrapped into RxJS streams. This means that you need to subscribe to them in order to excute the streams underlying logic (e.g. continue into the controller logic after an interceptor has been excuted).
107+
108+
An example of this can be seen below:
109+
110+
```typescript
111+
async listen(callback: () => void) {
112+
const echoHandler = this.messageHandlers.get('echo');
113+
const streamOrResult = await echoHandler('Hello World');
114+
if (isObservable(streamOrResult)) {
115+
streamOrResult.subscribe();
116+
}
117+
console.log(streamOrResult);
118+
callback();
119+
}
120+
```
121+
106122
#### Client proxy
107123

108124
As we mentioned in the first section, you don't necessarily need to use the `@nestjs/microservices` package to create microservices, but if you decide to do so and you need to integrate a custom strategy, you will need to provide a "client" class too.

0 commit comments

Comments
 (0)