Skip to content

(rabbitmq) add logging to errorHandler in case a deserialization failure of a message #1223

@Loki-Afro

Description

@Loki-Afro

When a rabbitmq consumer gets a malformed message, completely empty, syntax error in json, undefined you name it. Consumer loops indefinitely by default without logging anything when requeue error handler is used (default) and setting up consumer programmatically.

the function in question that is needed to break
https://github.com/golevelup/nestjs/blob/master/packages/rabbitmq/src/amqp/connection.ts#L597
example code

import { AmqpConnection, defaultNackErrorHandler, } from '@golevelup/nestjs-rabbitmq';
...
	await amqpConnection.createSubscriber<T>(
		(payload) => {
			if (!payload) {
				throw new Error(`Received empty payload for ${event} event`);
			}

			return handler(payload);
		},
		{
			exchange: 'someExchange',
			routingKey: 'someRoutingKey',
			queue: 'someQueue',
			errorHandler: <can be overwritten here, log here and return nack >
		},

The default errorHandler silently requeues the message, leading to an infinite loop.

I'm okay with the default of requeue, however i'd prefer to force the user to decide what behavior is wanted here since this is very much use case dependent.
And that in case of an error that error gets logged before a certain action is being done

What do you think about that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions