#An unsupported event was received. It has been negative acknowledged, so it will not be re-delivered

1 messages · Page 1 of 1 (latest)

knotty mountain
#

Please provide more information

#

And ur code snippets

magic briar
#

This is a NestJS microservices error message:

An unsupported event was received. It has been negative acknowledged, so it will not be re-delivered
magic briar
# knotty mountain And ur code snippets

Ok here are the code fragments, my code is almost 1 on 1 from the NestJS docs:

===Client===
Constructor:

    @Inject(EventTypes.CandleEvent)
    private readonly ce: ClientProxy,

Emit:

          const event = new CandleEvent(
            new CandleMessage(_identifier, v4(), {
              ticker: ticker.symbol,
              timeframe: timeframe,
              open: candle.open,
              top: candle.top,
              low: candle.low,
              close: candle.close,
              volume: candle.volume,
              timestamp: new Date(candle.timestamp),
            })
          );
          this.ce.emit(EventTypes.CandleEvent, event);

Register:

@Module({
  imports: [
    ClientsModule.registerAsync([
      {
        name: EventTypes.CandleEvent,
        inject: [ConfigService],
        useFactory: (config: ConfigService) => ({
          transport: Transport.RMQ,
          options: rabbitOptions(config, EventTypes.CandleEvent),
        }),
      },
    ]),

rabbitOptions:

export const rabbitTransport = (
  configService: ConfigService,
  queue: (typeof EventTypes)[keyof typeof EventTypes]
): RmqOptions => {
  const host = configService.get("RABBIT_HOST");
  const port = configService.get("RABBIT_PORT");
  const user = configService.get("RABBIT_USER");
  const password = configService.get("RABBIT_PASSWORD");

  return {
    transport: Transport.RMQ,
    options: {
      urls: [`amqp://${user}:${password}@${host}:${port}`],
      queue: queue,
      queueOptions: {
        durable: false,
      },
      noAck: false,
    },
  };
};

export const rabbitOptions = (
  configService: ConfigService,
  queue: (typeof EventTypes)[keyof typeof EventTypes]
): unknown => {
  const transport = rabbitTransport(configService, queue);
  return {
    urls: transport.options.urls,
    queue: transport.options.queue,
    queueOptions: transport.options.queueOptions,
    noAck: true,
  };
};

===Microservice===
Just a controller with decorators:

@Controller()
@UseFilters()
export class TaController {
  private readonly logger = new Logger(TaController.name);

  @EventPattern(EventTypes.CandleEvent)
  async candleEvent(
    @Payload() candle: CandleEvent,
    @Ctx() context: RmqContext
  ) {
    this.logger.log("Received CandleEvent", candle);
    this.logger.log("context.getMessage()", context.getMessage());
    const channel = context.getChannelRef();
    channel.ack(context.getMessage());
  }

And in main:

await bootstrapRabbitMicroservice(app, EventTypes.CandleEvent);

bootstrapRabbitMicroservice: (uses rabbitTransport from rabbitOptions which the client also uses above)

export const bootstrapRabbitMicroservice = async (
  app: INestApplication,
  event: (typeof EventTypes)[keyof typeof EventTypes]
): Promise<INestMicroservice> => {
  const microserviceRabbit = app.connectMicroservice<MicroserviceOptions>(
    rabbitTransport(app.get(ConfigService), event)
  );

  Logger.log(
    `Microservice using RabbitMQ for >> ${event} << is initialized...`
  );

  return microserviceRabbit;
};
#

More information:
It seems the microservice gets the message, but is somehow not able to interpret it

winter ocean
#

What is the underlyinf type of EventType.CandleEvent?

magic briar
#

it looks like this:

export const EventTypes = {
  CandleEvent: "CANDLE_EVENT",
};
#

so its basically just a string

winter ocean
#

Oh I see. In connectMicrosetvice you need to pass an object with { strategy: TheTransport }

magic briar
winter ocean
#

I see, I thouht it was a custom strategy, not the built in one 🤦‍♂️

magic briar
#

app.connectMicroservice<MicroserviceOptions>(

#

the MicroserviceOptions are RmqOptions

#

the error occurs everytime the client sends an event, and the microservice is supposed to receive it, but then instead says this

#

so it looks like Rabbit is delivering (or getting pulled from) but there is something wrong with the format

#

after some digging i found that there long ago there where strict requirements that the object we need to send over this needs to have a {data: dataObj} structure, but thats not the case anymore right?

#

does it matter that the client and microservice are running in the same server? (main.ts)

#

i am feeling i am missing something super obvious