-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9586 from nestjs/fix/propagate-kafka-errors
feat(microservices): add kafka retriable exception, auto-unwrap payloads
- Loading branch information
Showing
11 changed files
with
170 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/microservices/deserializers/kafka-request.deserializer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { IncomingEvent, IncomingRequest } from '../interfaces'; | ||
import { KafkaRequest } from '../serializers/kafka-request.serializer'; | ||
import { IncomingRequestDeserializer } from './incoming-request.deserializer'; | ||
|
||
export class KafkaRequestDeserializer extends IncomingRequestDeserializer { | ||
mapToSchema( | ||
data: KafkaRequest, | ||
options?: Record<string, any>, | ||
): IncomingRequest | IncomingEvent { | ||
if (!options) { | ||
return { | ||
pattern: undefined, | ||
data: undefined, | ||
}; | ||
} | ||
return { | ||
pattern: options.channel, | ||
data: data?.value ?? data, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './base-rpc-exception-filter'; | ||
export * from './kafka-retriable-exception'; | ||
export * from './rpc-exception'; |
17 changes: 17 additions & 0 deletions
17
packages/microservices/exceptions/kafka-retriable-exception.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { RpcException } from './rpc-exception'; | ||
|
||
/** | ||
* Exception that instructs Kafka driver to instead of introspecting | ||
* error processing flow and sending serialized error message to the consumer, | ||
* force bubble it up to the "eachMessage" callback of the underlying "kafkajs" package | ||
* (even if interceptors are applied, or an observable stream is returned from the message handler). | ||
* | ||
* A transient exception that if retried may succeed. | ||
* | ||
* @publicApi | ||
*/ | ||
export class KafkaRetriableException extends RpcException { | ||
public getError(): string | object { | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters