nestjs/nest · error

An unsupported event was received. It has been negative ackn

Error message

An unsupported event was received. It has been negative acknowledged, so it will not be re-delivered. Pattern: ${pattern}

What it means

ServerRMQ.handleEvent received an event (a packet without an `id`, fire-and-forget) whose pattern matches no @EventPattern handler. In manual-ack mode (noAck false) the server nacks the message with requeue=false — RabbitMQ drops it permanently, no redelivery — and returns this warning. Unlike the message case there is no reply channel, so the emitting client gets no error: the event is simply lost, which makes this the more dangerous variant.

Source

Thrown at packages/microservices/server/server-rmq.ts:358

            properties.replyTo,
            properties.correlationId,
            rmqContext,
          );

        response$ && this.send(response$, publish);
      },
    );
  }

  public async handleEvent(
    pattern: string,
    packet: ReadPacket,
    context: RmqContext,
  ): Promise<any> {
    const handler = this.getHandlerByPattern(pattern);
    if (!handler && !this.noAck) {
      this.channel!.nack(context.getMessage() as Message, false, false);
      return this.logger.warn(RMQ_NO_EVENT_HANDLER`${pattern}`);
    }
    return super.handleEvent(pattern, packet, context);
  }

  public sendMessage<T = any>(
    message: T,
    replyTo: any,
    correlationId: string,
    context: RmqContext,
  ): void {
    const outgoingResponse = this.serializer.serialize(
      message as unknown as OutgoingResponse,
    );
    const options = outgoingResponse.options;
    delete outgoingResponse.options;

    const buffer = Buffer.from(JSON.stringify(outgoingResponse));
    const sendOptions = { correlationId, ...options };

View on GitHub (pinned to dd75d7bd8c)

Solutions

  1. Align the pattern literal on producer and consumer (exact string or shared constant); object patterns must serialize identically.
  2. Use a dedicated queue per microservice so events are never round-robined to services without the handler.
  3. Add a dead-letter exchange to the queue so dropped unsupported events are inspectable, and alert on its depth.
  4. Deploy order matters: register the @EventPattern consumer before producers start emitting the new pattern.
  5. Purge queues after renaming or removing event patterns.

Example fix

// before
// producer
this.client.emit('order-created', order);
// consumer
@EventPattern('order_created') // underscore vs dash -> nack, event lost silently

// after
export const ORDER_CREATED = 'order-created'; // shared constants package
this.client.emit(ORDER_CREATED, order);
@EventPattern(ORDER_CREATED)
onOrderCreated(@Payload() order: Order) { /* ... */ }
Defensive patterns

Strategy: validation

Validate before calling

// events are fire-and-forget: no error comes back, so validate before emit
export const EVENTS = ['order-created', 'order-cancelled'] as const;
export type DomainEvent = (typeof EVENTS)[number];

function assertKnownEvent(e: string): asserts e is DomainEvent {
  if (!(EVENTS as readonly string[]).includes(e)) {
    throw new Error(`Unknown event '${e}': consumer has no @EventPattern for it`);
  }
}

assertKnownEvent(eventName);
this.client.emit(eventName, payload);

Type guard

const EVENTS = ['order-created', 'order-cancelled'] as const;
type DomainEvent = (typeof EVENTS)[number];
const isDomainEvent = (e: string): e is DomainEvent =>
  (EVENTS as readonly string[]).includes(e);

Prevention

When it happens

Trigger: client.emit(pattern, payload) where the pattern does not exactly match any @EventPattern(pattern) on the server (typo, casing, or object-pattern JSON key-order mismatch). Also events published to the service's queue by external producers without the expected {pattern, data} shape, and rolling deploys where a producer emits new event names before the consumer registers them.

Common situations: Event-name typos between producer and consumer services; renaming events without draining queues; several services sharing one queue so events land on an instance lacking the handler; external systems publishing directly to the queue; new events deployed producer-first.

Related errors


AI-assisted analysis of nestjs/nest@dd75d7bd8c (2026-08-21). Data as JSON: /api/errors/bf90fbbaf7051fe1. Report an issue: GitHub.