Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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';
20 changes: 19 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,15 @@ export const rabbitmqConnectionFactory = {
}),
inject: [ConfigService],
} as ClientsProviderAsyncOptions;

export const createRMQMicroservice = (queueName: string) => {
return NestFactory.createMicroservice<MicroserviceOptions>(AppModule, {
transport: Transport.RMQ,
options: {
urls: ['amqp://admin:admin@localhost:5672'], // 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 handleNftGeneration(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

}
}
8 changes: 8 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ 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';

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 mintManagementChannel = await createRMQMicroservice(
MINT_MANAGEMENT_QUEUE,
);

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

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

await mintManagementChannel.listen();
console.log('Listening to mint management channel');
} catch (err) {
console.log('Error starting app!', err);
process.exit(1);
Expand Down