Files
What you'll learn
- Write a CustomTransportStrategy: a Server subclass whose listen() receives messages and hands them to the handlers Nest registered, found with getHandlerByPattern()
- Reply through Server.send() and transformToObservable(), so values, promises, streams and errors all become WritePackets
- Write a ClientProxy subclass: publish() with a callback for each reply and a teardown, dispatchEvent() for events, connect() and close()
- Plug both in with createMicroservice's strategy and ClientsModule's customClass, and know that handlers and callers do not change
Press Run tests to start the app. Its log appears here.Graded endpoints
The client published { cmd: 'find-all' } to 'requests', the server found the handler and published its reply to 'replies.gateway' with the request's id
The data travels with the pattern, and the reply goes to the call that asked
The handler's RpcException became an err packet through Server.send(), and the gateway's operator made it a 404
The handler returns an Observable: two replies with the same id, the last marked isDisposed, and the client passes each one on
The server replies with the error itself, so the caller gets a 502 instead of waiting forever
emit() reaches the client's dispatchEvent(), which publishes to 'events'
The server passed the event to Nest's handleEvent(), and the handler recorded the adopter
The bus carried six requests and one event: none of this went over TCP