This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Define the Kafka broker and topic | |
BROKER_LIST="localhost:9092" | |
TOPIC="mfaf.exampleTopic" | |
# Loop to simulate load test | |
while true; do | |
# Generate some random JSON data and save it to a file | |
# echo "{\"key\": \"value\"}" > m.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"header":{"version":"1.0","timestamp":"xxxx","orgService":"xxxx","tid":"xxxx","lastTid":"xxxx","session":"xxxx","transaction":"xxxx","communication":"unicast|multicast|broadcast","groupTags":[],"identity":{"device":"xxxxx","public":"xxxxx","user":"xxxxx"},"tmfSpec":"none|TMFxxx","baseApiVersion":"none|4.0.0|4.1.0|5.0.0","schemaVersion":"1.0.0"},"body":{"example":"xxx","@referredType":"1111"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Set the parameters | |
bootstrap_server="localhost:9092" | |
topic="mfaf.exampleTopic" | |
messages_per_iteration=100 | |
total_iterations=10 | |
# JSON message template | |
json_template='{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
^ ?(.+)$ | |
"$1", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function timeToDecimal(timeString) { | |
var timeParts = timeString.split(':'); | |
var hours = parseInt(timeParts[0]); | |
var minutes = parseInt(timeParts[1]) || 0; | |
var seconds = parseInt(timeParts[2]) || 0; | |
var decimalHours = hours + (minutes / 60) + (seconds / 3600); | |
return decimalHours; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function formatDate(dateString) { | |
const date = new Date(dateString); | |
const options = { | |
day: '2-digit', | |
month: '2-digit', | |
year: 'numeric', | |
timeZone: 'Asia/Bangkok', | |
//timeZoneName: 'short' | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// kafka-consumer.service.ts | |
import { Injectable } from '@nestjs/common'; | |
import { Kafka, Consumer, EachMessagePayload } from 'kafkajs'; | |
@Injectable() | |
export class KafkaConsumerService { | |
private kafkaConsumer: Consumer; | |
private isConsuming: boolean; | |
constructor() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// kafka-producer.service.ts | |
import { Injectable } from '@nestjs/common'; | |
import { Kafka } from 'kafkajs'; | |
@Injectable() | |
export class KafkaProducerService { | |
private kafkaProducer; | |
constructor() { | |
this.kafkaProducer = new Kafka({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
function readFilePromise(fileName, encoding, cb) { | |
fs.readFile(fileName, encoding, cb); | |
} | |
async function run() { | |
try { | |
const data = await (async () => { | |
return new Promise(async (resolve) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common'; | |
import { ConfigService } from '@nestjs/config'; | |
import { Kafka, Consumer, Producer, EachMessagePayload } from 'kafkajs'; | |
import { removePathTraversalCharacters } from 'src/app.module'; | |
@Injectable() | |
export class KafkaService implements OnModuleInit, OnModuleDestroy { | |
private kafka: Kafka; | |
private producer: Producer; | |
private consumer: Consumer; |