0
0
NestJSframework~5 mins

Event patterns (event-based) in NestJS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an event pattern in NestJS event-based communication?
An event pattern is a unique identifier string used to listen for or emit specific events between microservices or modules in NestJS. It helps match events with their handlers.
Click to reveal answer
beginner
How do you define an event handler for a specific event pattern in NestJS?
You use the @EventPattern('patternName') decorator on a method inside a controller or service. This method will run when an event with that pattern is received.
Click to reveal answer
intermediate
What is the difference between @EventPattern and @MessagePattern in NestJS?
@EventPattern listens for events that do not expect a response (fire-and-forget). @MessagePattern listens for messages that expect a response (request-response).
Click to reveal answer
beginner
How do you emit an event with a pattern in NestJS?
You use the ClientProxy's emit method with the event pattern string and the data payload. For example: client.emit('order_created', { id: 1 }).
Click to reveal answer
intermediate
Why are event patterns useful in microservice architectures?
They allow services to communicate asynchronously and loosely coupled by sending and listening to events identified by patterns, improving scalability and flexibility.
Click to reveal answer
Which decorator do you use to listen for an event pattern in NestJS?
A@SubscribeEvent
B@MessagePattern
C@EventPattern
D@ListenEvent
What method do you call to emit an event from a NestJS client proxy?
Aemit()
Bdispatch()
Csend()
Dtrigger()
What is the main difference between @EventPattern and @MessagePattern?
A@EventPattern expects a response, @MessagePattern does not
B@EventPattern is fire-and-forget, @MessagePattern expects a response
C@EventPattern is for HTTP, @MessagePattern is for TCP
DThey are the same
In NestJS, what does an event pattern usually look like?
AA string identifier
BA function
CA boolean value
DA number
Why use event patterns in microservices?
ATo avoid using events
BTo enable synchronous communication
CTo tightly couple services
DTo allow asynchronous, loosely coupled communication
Explain how to create and handle an event pattern in NestJS.
Think about how you listen and send events using patterns.
You got /4 concepts.
    Describe the benefits of using event patterns in a microservice system.
    Consider how events help services work independently.
    You got /4 concepts.