Skip to content
This repository has been archived by the owner on Dec 28, 2023. It is now read-only.

Commit

Permalink
Added a listener service
Browse files Browse the repository at this point in the history
  • Loading branch information
emito-k committed Oct 25, 2023
1 parent bb35e84 commit 32a3367
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
5 changes: 3 additions & 2 deletions backend/events-listener/controllers/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import admin from "firebase-admin";

async function processReceivedMessage() {
try{
const queueName = 'notifications';
const queueName = 'events-queue';
const receivedMsg = await receiveMessageFromQueue(queueName);
if(receivedMsg !== null){
console.log("Received message:", receivedMsg);
handleNotification(receivedMsg);
// handleNotification(receivedMsg);

}else {
console.log("No messages received...");
}
Expand Down
2 changes: 1 addition & 1 deletion backend/events-listener/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ const PORT = 8006;
// initialize body-parser middleware
app.use(bodyParser.json()); // will be using Json data
app.use('/notifications', notify);
app.get('/', (req, res) => res.send(" Notifications services"));
app.get('/', (req, res) => res.send(" Events listener service"));
app.listen(PORT, () => console.log(`Server running on port: http://localhost:${PORT}`));
6 changes: 3 additions & 3 deletions backend/gateway-service/routes.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"/c": "https://event-chats-service-wcjsbin3oq-uc.a.run.app",
"/p": "https://event-posts-service-old-wcjsbin3oq-uc.a.run.app",
"/e": "http://localhost:8004",
"/u": "https://user-management-service-wcjsbin3oq-uc.a.run.app",
"/e": "https://events-service-wcjsbin3oq-uc.a.run.app",
"/u": "http://localhost:8002",
"/n": "https://notifications-service-wcjsbin3oq-uc.a.run.app",
"/posts": "https://xpose-posts-service-wcjsbin3oq-uc.a.run.app"
"/posts": "http://127.0.0.1:5000"
}
14 changes: 14 additions & 0 deletions backend/user-management-service/controllers/deleteUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import admin from "firebase-admin";
import User from '../data-access/models/user.table.js';
import Friendship from '../data-access/models/friendship.table.js';
import { Op } from 'sequelize';
import { sendMessageToQueue } from '../sender.js';
import MessageBuilder from './messagebuilder.js';

let users = [];
export const deleteUser = async (req, res) => {
Expand Down Expand Up @@ -32,6 +34,18 @@ export const deleteUser = async (req, res) => {
}

});

// send delete user message to rabbitmq
// const queueName = 'notifications';
console.log('Sending delete user message to rabbitmq');
const message = new MessageBuilder().setType("delete_user").setValue({deleted_user_id: userId}).build();
console.log('Message: ', message);

sendMessageToQueue('posts-queue', message);
sendMessageToQueue('events-queue', message);

console.log(`Messages sent to rabbitmq`);

res.status(200).json({message:`User with the id ${userId} deleted from DB successfuly`});

} catch(error) {
Expand Down

0 comments on commit 32a3367

Please sign in to comment.