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

Kafka #147

Merged
merged 8 commits into from
Jan 18, 2024
Merged

Kafka #147

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
15 changes: 12 additions & 3 deletions .github/workflows/clinic-microservice-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ name: Clinic CI

on:
push:
branches: [ "main" ]
branches: ['main']
pull_request:
branches: [ "main" ]
branches: ['main']

jobs:
lint-and-test-clinic:
Expand All @@ -17,6 +17,12 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2

- name: Run Docker
run: docker-compose up -d

- name: Wait for Kafka to be ready
run: npx wait-on tcp:127.0.0.1:${{ secrets.KAFKA_PORT }} && echo "Kafka is ready!"

- name: Setup Node.js
uses: actions/setup-node@v2
with:
Expand All @@ -33,6 +39,9 @@ jobs:
- name: Run Tests (Clinic Microservice)
run: npm run test
working-directory: clinic

env:
MONGO_URI_TEST: ${{ secrets.MONGO_URI_TEST }}

ZOOKEEPER_PORT: ${{ secrets.ZOOKEEPER_PORT }}
KAFKA_PORT: ${{ secrets.KAFKA_PORT }}
ZOOKEEPER_HOST_NAME: ${{ secrets.ZOOKEEPER_HOST_NAME}}
21 changes: 2 additions & 19 deletions authentication/src/api/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ export const user = (app) => {
}
});

//

//
app.delete('/users/:id', async (req, res) => {
try {
const userId = req.params.id;
Expand Down Expand Up @@ -173,8 +170,9 @@ export const user = (app) => {
}
});

app.post('/check-admin/:request', async (req, res) => {
app.post('/admins/:request', async (req, res) => {
try {
let signupData = null;
const requestFrom = req.params.request; // clinic, pharmacy
const userName = req.body.userName;
const email = req.body.email;
Expand Down Expand Up @@ -203,21 +201,6 @@ export const user = (app) => {
throw new Error('invalid system');
}

res.status(OK_REQUEST_CODE_200).end();
} catch (error) {
if (error.response) {
res
.status(BAD_REQUEST_CODE_400)
.send({ message: error.response.data.errMessage });
} else {
res.status(ERROR_STATUS_CODE).send({ message: error.message });
}
}
});

app.post('/admins/:request', async (req, res) => {
try {
let signupData = null;
switch (requestFrom) {
case CLINIC_REQ:
signupData = await axios.post(ADMIN_Clinic_SIGNUP_URL, req.body);
Expand Down
2 changes: 0 additions & 2 deletions authentication/src/tests/api-tests/AuthenticationAPI.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ describe('POST /admins/:request', () => {
const type = PHARMACY_ADMIN_ENUM;
const email = faker.internet.email();

// const userId = faker.database.mongodbObjectId();
// const userName = faker.internet.userName();
const user = new User(generateUser(userId, email, userName, type));
await user.save();
const res = await request(app).post(`/admins/${PHARMACY_REQ}`).send({ userId: userId, type: type, email: email, userName: userName, password: faker.internet.password() });
Expand Down
15 changes: 9 additions & 6 deletions clinic/src/producers/AppointmentProducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ import {
OK_STATUS_CODE,
} from '../utils/Constants.js';

export const appointmentProducer = (app) => {
const client = new KafkaNode.KafkaClient({ kafkaHost: 'localhost:9092' });
const producer = new KafkaNode.Producer(client);
const client = new KafkaNode.KafkaClient({ kafkaHost: 'localhost:9092' });
const producer = new KafkaNode.Producer(client);

const appointmentProducer = (app) => {
const kafka_topic = 'notifications';

producer.on('ready', async function () {
console.log('Appointment Producer is ready');
producer.on('ready', function () {
console.log('Appointment producer is ready');
});

producer.on('error', function (err) {
console.log('Appointment Producer is in error state');
console.log('Appointment producer is in error state');
console.log(err);
});

Expand Down Expand Up @@ -58,3 +59,5 @@ export const appointmentProducer = (app) => {
}
});
};

export { appointmentProducer, producer };
2 changes: 2 additions & 0 deletions clinic/src/utils/TestingUtils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { producer } = require('../producers/AppointmentProducer.js');
const mongoose = require('mongoose');
const dotenv = require('dotenv');
dotenv.config();
Expand All @@ -14,6 +15,7 @@ const connectDBTest = async () => {

const disconnectDBTest = async () => {
try {
producer.close();
const collections = mongoose.connection.collections;

for (const key in collections) {
Expand Down
26 changes: 26 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: '3.8'

services:
zookeeper:
image: wurstmeister/zookeeper
ports:
- ${ZOOKEEPER_PORT}:${ZOOKEEPER_PORT}
environment:
- ALLOW_ANONYMOUS_LOGIN=yes

kafka:
image: wurstmeister/kafka
container_name: kafka
ports:
- ${KAFKA_PORT}:${KAFKA_PORT}
volumes:
- ./data/kafka:/var/run/docker.sock
environment:
- KAFKA_BROKER_ID=1
- KAFKA_LISTENERS=PLAINTEXT://:${KAFKA_PORT}
- KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://localhost:${KAFKA_PORT}
- KAFKA_ZOOKEEPER_CONNECT=${ZOOKEEPER_HOST_NAME}:${ZOOKEEPER_PORT}
- KAFKA_CREATE_TOPICS=notifications:1:1,out_of_stock:1:1
- ALLOW_PLAINTEXT_LISTENER=yes
depends_on:
- zookeeper
Loading