Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I keep my RabbitMQ worker functions active as Lambda functions?

These worker functions are RabbitMQ consumers that process incoming requests and reply with responses.

I’m looking for guidance on how to keep these worker functions always active after deploying the Lambda function. What configurations or practices can help achieve this?

// app.js
import e from 'express';
import cors from 'cors';
import bodyParser from 'body-parser';
import morgan from 'morgan';
import 'dotenv/config.js';
import mongoose from 'mongoose';
import SwaggerRouter from './swagger.js';
import logger from './logger.js';
import StartUpRouter from './routes/user_founder.js'
import VCRouter from './routes/user_vc.js';
import SuperAdminRouter from './routes/superadmin.js';
import { handleVCListRequest, startTokenValidationWorker, startUserValidationWorker, startVCDataWorker } from './workers/messageQueueWorker.js';
import { startWorker } from './services/rabbitMQService.js';
import { processMessage } from './workers/emailWorker.js';

const app = e();
app.use(cors());
app.use(morgan('dev'));
app.use(bodyParser.json());
app.use(SwaggerRouter);

// ...other routes and middleware...

mongoose.connect(process.env.MONGO_URL, { useUnifiedTopology: true, useNewUrlParser: true })
.then(() => {
  app.listen(process.env.PORT || 4001);
  logger.info({listening: `Server is Processing on ${process.env.PORT}.`});
  logger.info({success: "Connected to AuthenticationService Database."});
  console.log({listening: `Server is Processing on ${process.env.PORT}.`});
  console.log({success: "Connected to Database."});

  startWorker(processMessage).catch((error) => {
    console.error('Error while sending email:', error.message);
  });

  startTokenValidationWorker().catch((error) => {
    logger.error('Error starting token validation worker:', error.message);
    console.error('Error starting token validation worker:', error.message);
  });

  // ...other worker functions...

  handleVCListRequest().catch((error) => {
    logger.error('Error starting vc list worker:', error.message)
    console.error('Error starting vc list worker:', error.message);
  });
})
.catch((err) => {
  logger.error({error: err.message});
  console.error({error: err});
});

export default app;

// lambda.js
import ServerlessHttp from "serverless-http";
import app from "./app.js";

export const handler = ServerlessHttp(app);

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

AWS Lambda is not the right service here, as a serverless compute service.

While you can keep a Lambda function warm, the nature and purpose of serverless architectures is to not keep services running 24/7.

RabbitMQ consumers, that should always be listening for messages, should be running on a service like ECS, EC2 etc. that use servers & can be available 24/7.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading