Skip to content

Commit

Permalink
added produce test message using redis connector
Browse files Browse the repository at this point in the history
  • Loading branch information
ofirelarat committed Sep 8, 2023
1 parent 9e6c99f commit 79528aa
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 20 deletions.
178 changes: 167 additions & 11 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
"react": "18.2.0",
"react-dom": "18.2.0",
"react-graph-vis": "^1.0.7",
"redis": "^4.6.8",
"uuidv4": "^6.2.13"
},
"devDependencies": {
"typescript": "5.0.2",
"prettier": "^2.8.8",
"@types/node": "18.15.5",
"@types/react": "18.0.28",
"@types/react-dom": "18.0.11"
"@types/react-dom": "18.0.11",
"prettier": "^2.8.8",
"typescript": "5.0.2"
}
}
11 changes: 5 additions & 6 deletions client/src/pages/api/test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { Pipeline } from '@/models/pipeline';
import { Connector, KafkaConnector } from '@/models/connector';
import { produceTest } from '@/tools/kafka';

const kafkaHandler = async (connector: KafkaConnector, pipeline: Pipeline, message: string) => {
await produceTest(connector, pipeline, message);
}
import { Connector, KafkaConnector, RedisConnector } from '@/models/connector';
import { produceTest as kafkaHandler } from '@/tools/kafka';
import { produceTest as redisHandler } from '@/tools/redis';

export default async function handler(
req: NextApiRequest,
Expand All @@ -19,6 +16,8 @@ export default async function handler(

if (connector.type === 'kafka') {
await kafkaHandler(connector as KafkaConnector, pipeline, message);
}else if(connector.type === 'redis'){
await redisHandler(connector as RedisConnector, pipeline, message);
}

res.status(200).json({ result: 'succeed' });
Expand Down
10 changes: 10 additions & 0 deletions client/src/tools/redis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import redis from 'redis';
import { RedisConnector } from "@/models/connector";
import { Pipeline } from "@/models/pipeline";

export const produceTest = async (connector: RedisConnector, pipeline: Pipeline, message: string) => {
const redisClient = redis.createClient({
url: `redis://${connector.host}:${connector.port}/0`
})
await redisClient.publish(pipeline.input.topic, message);
}

0 comments on commit 79528aa

Please sign in to comment.