Skip to content

RabbitSubscribe method is loading before my constructor #899

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
laxmaneasecommerce opened this issue Dec 25, 2024 · 2 comments
Open

RabbitSubscribe method is loading before my constructor #899

laxmaneasecommerce opened this issue Dec 25, 2024 · 2 comments

Comments

@laxmaneasecommerce
Copy link

laxmaneasecommerce commented Dec 25, 2024

I am using below service to consume my queue

import { Controller } from '@nestjs/common';
import {
  RabbitSubscribe, defaultNackErrorHandler,
} from '@golevelup/nestjs-rabbitmq';
import { WebhookRabbitMqListener } from 'commerce-library';
import { QueueService } from './service/queue.service';

@Controller()
export class QueueMessageConsumer {

  constructor(private readonly warehouseService: QueueService
  ) { }
  @RabbitSubscribe({
    queue: 'V2webhook_queue',
    queueOptions: {
      durable: true
    },
    errorHandler: defaultNackErrorHandler,
  })
  async webhookV2EventsQueue({ data }: { data: WebhookRabbitMqListener }): Promise<any> {
    try {

      await this.warehouseService.processWebhookMessageQueue(data, 'V2webhook_queue')
    } catch (error) {
      console.log(error);
    }
  }
}

I am getting warehouseService is undefine in

the webhookV2EventsQueue

please help me
I am stuck

@WonderPanda
Copy link
Collaborator

Can you try defining the webhookv2EventsQueue as an arrow function instead? Eg:

webhookv2EventsQueue = async (data) => {}

You might be losing the proper this context which would prevent you from accessing other methods or properties on the parent class.

@underfisk
Copy link
Contributor

@laxmaneasecommerce Are you able to share more information of your dependencies such as Nestjs Version, @golevelup/rabbitmq package version, nodejs etc?
Also including a stack trace would be ideal because the code you've pasted works just fine when I try to reproduce it locally

@underfisk underfisk added Pending Repro A repro is pending in order to replicate the issue waiting for more info and removed Pending Repro A repro is pending in order to replicate the issue labels Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants