Skip to content

Conversation

@ormelaver-cyber
Copy link

@ormelaver-cyber ormelaver-cyber commented Dec 18, 2025

Problem

When RabbitMQ consumers receive messages with invalid JSON or incorrect content-type headers, parsers.in() throws an error that isn't caught, causing:

  • Infinite retry loops (message never ACKed/NACKed)
  • Consumer crashes
  • No way for clients to handle poison messages gracefully

Solution

Use the existing _rejectMessageAfterProcess function with requeue=false and body={} to prevent infinite processing and throw an error to enable the client to handle it.
As part of _rejectMessageAfterProcess , an afterProcessMessage hook is triggered.
This way, clients can either wrap their call in a try-catch block and handle the error, or register to the afterProcessMessage hook and handle the error there.

Changes

  • Wrap parsers.in(msg) in try-catch block
  • If a SyntaxError is thrown: reject with requeue=false and throw to propagate error upstream.

Usage Example - Hook Registration

bus.hooks.consumer.afterProcessMessage(async ({ error, message, content }) => {
	if (error) {
             // Your error handling logic goes here
	}
});

Backward Compatibility

✅ Client doesn't have to register to the afterProcessMessage hook
✅ An error is thrown regardless - the client decides how to handle it

@ormelaver-cyber ormelaver-cyber marked this pull request as ready for review December 18, 2025 11:56
@shamil shamil removed their assignment Dec 22, 2025
@shamil shamil removed their assignment Dec 23, 2025
@shamil shamil removed their assignment Dec 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants