Skip to content
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

RabbitSubscribe method is loading before my constructor #899

Open
laxmaneasecommerce opened this issue Dec 25, 2024 · 1 comment
Open

RabbitSubscribe method is loading before my constructor #899

laxmaneasecommerce opened this issue Dec 25, 2024 · 1 comment

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants