Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/common/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ export const DEFAULT_PAGE_SIZE = 20;
export const DEFAULT_PAGE = 1;

export const TOKEN_EXPIRATION_TIME = '30d';

export const MINT_MANAGEMENT_QUEUE = 'mint_management';
23 changes: 22 additions & 1 deletion src/common/rabbitmq/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { ConfigService } from '@nestjs/config';
import { ClientsProviderAsyncOptions, Transport } from '@nestjs/microservices';
import { NestFactory } from '@nestjs/core';
import {
ClientsProviderAsyncOptions,
MicroserviceOptions,
Transport,
} from '@nestjs/microservices';

import { AppModule } from 'src/app.module';
import {
NFT_GENERATION_QUEUE,
RABBITMQ_SERVICE_NAME,
Expand All @@ -22,3 +28,18 @@ export const rabbitmqConnectionFactory = {
}),
inject: [ConfigService],
} as ClientsProviderAsyncOptions;

export const createRMQMicroservice = (
queueName: string,
configService: ConfigService,
) => {
return NestFactory.createMicroservice<MicroserviceOptions>(AppModule, {
transport: Transport.RMQ,
options: {
urls: [configService.get('RABBITMQ_URL') as string], // TODO: Change path
queue: queueName,
prefetchCount: 1,
queueOptions: { durable: false },
},
});
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Controller, Get, Query } from '@nestjs/common';
import { EventPattern } from '@nestjs/microservices';

import { CampaignPledgeService } from '../../services/campaign-pledge/campaign-pledge.service';
import { APIResponse } from 'src/common/types';
import { CampaignPledgeQueryDto } from '../../dto/campaigns-pledge-query-dto';
import { CurrentUser } from 'src/decorators/currentUser.decorator';
import { MINT_MANAGEMENT_QUEUE } from 'src/common/constants';

@Controller('campaigns-pledge')
export class CampaignsPledgeController {
Expand All @@ -25,4 +27,9 @@ export class CampaignsPledgeController {
});
return { data: campaigns };
}

@EventPattern(MINT_MANAGEMENT_QUEUE)
async handleMint(data) {
console.log('Received data: ', data);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not necessary for now as it's executing without exceptions, i just console.log something. But let me know if i should add it

}
}
10 changes: 10 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@ import mongoose from 'mongoose';
import { AppModule } from './app.module';
import { AllExceptionsFilter } from './middlewares/filters/exception.filter';
import { JwtAuthGuard } from './features/auth/guards/auth.guard';
import { createRMQMicroservice } from './common/rabbitmq';
import { MINT_MANAGEMENT_QUEUE } from './common/constants';
import { ConfigService } from '@nestjs/config';

const { API_PORT, NODE_ENV } = process.env;

async function bootstrap() {
const isProductionEnv = NODE_ENV === 'production';
const app = await NestFactory.create(AppModule);
const adapterHost = app.get(HttpAdapterHost);
const queue = await createRMQMicroservice(
MINT_MANAGEMENT_QUEUE,
new ConfigService(),
);

app.use(helmet());
app.use(morgan('combined'));
Expand All @@ -39,6 +46,9 @@ async function bootstrap() {

await app.listen(API_PORT);
console.log(`NestJS API listening on port ${API_PORT}`);

await queue.listen();
console.log('RabbitMQ service running');
} catch (err) {
console.log('Error starting app!', err);
process.exit(1);
Expand Down