diff --git a/utilities/project-factory/src/server/config/index.ts b/utilities/project-factory/src/server/config/index.ts index 9c181886dbd..83540f022a5 100644 --- a/utilities/project-factory/src/server/config/index.ts +++ b/utilities/project-factory/src/server/config/index.ts @@ -16,7 +16,7 @@ const getDBSchemaName = (dbSchema = "") => { } // Configuration object containing various environment variables const config = { - isCallGenerateWhenDeliveryConditionsDiffer:true, + isCallGenerateWhenDeliveryConditionsDiffer: true, enableDynamicTargetTemplate: true, prefixForMicroplanCampaigns: "MP", excludeHierarchyTypeFromBoundaryCodes: false, @@ -62,6 +62,7 @@ const config = { KAFKA_CREATE_GENERATED_RESOURCE_DETAILS_TOPIC: process.env.KAFKA_CREATE_GENERATED_RESOURCE_DETAILS_TOPIC || "create-generated-resource-details", KAFKA_SAVE_PROCESS_TRACK_TOPIC: process.env.KAFKA_SAVE_PROCESS_TRACK_TOPIC || "save-process-track", KAFKA_UPDATE_PROCESS_TRACK_TOPIC: process.env.KAFKA_UPDATE_PROCESS_TRACK_TOPIC || "update-process-track", + KAFKA_TEST_TOPIC: "test-topic-project-factory", }, // Database configuration diff --git a/utilities/project-factory/src/server/kafka/Listener.ts b/utilities/project-factory/src/server/kafka/Listener.ts index e0ea04ad8b1..4c0742e09d0 100644 --- a/utilities/project-factory/src/server/kafka/Listener.ts +++ b/utilities/project-factory/src/server/kafka/Listener.ts @@ -17,7 +17,8 @@ const kafkaConfig: ConsumerGroupOptions = { // Topic Names const topicNames = [ config.kafka.KAFKA_START_CAMPAIGN_MAPPING_TOPIC, - config.kafka.KAFKA_PROCESS_CAMPAIGN_MAPPING_TOPIC + config.kafka.KAFKA_PROCESS_CAMPAIGN_MAPPING_TOPIC, + config.kafka.KAFKA_TEST_TOPIC ]; // Consumer Group Initialization diff --git a/utilities/project-factory/src/server/kafka/Producer.ts b/utilities/project-factory/src/server/kafka/Producer.ts index 4c1e56dcd71..10938d880fd 100644 --- a/utilities/project-factory/src/server/kafka/Producer.ts +++ b/utilities/project-factory/src/server/kafka/Producer.ts @@ -12,9 +12,33 @@ const kafkaClient = new KafkaClient({ // Creating a new Kafka producer instance using the Kafka client const producer = new Producer(kafkaClient, { partitionerType: 2 }); // Using partitioner type 2 +// Function to send a test message to check broker availability +const checkBrokerAvailability = () => { + const payloads = [ + { + topic: config.kafka.KAFKA_TEST_TOPIC, + messages: JSON.stringify({ message: 'Test message to check broker availability' }), + }, + ]; + + producer.send(payloads, (err, data) => { + if (err) { + if (err.message && err.message.toLowerCase().includes('broker not available')) { + logger.error('Broker not available. Shutting down the service.'); + shutdownGracefully(); + } else { + logger.error('Error sending test message:', err); + } + } else { + logger.info('Test message sent successfully:', data); + } + }); +}; + // Event listener for 'ready' event, indicating that the producer is ready to send messages producer.on('ready', () => { logger.info('Producer is ready'); // Log message indicating producer is ready + checkBrokerAvailability(); // Check broker availability by sending a test message }); // Event listener for 'error' event, indicating that the producer encountered an error diff --git a/utilities/project-factory/src/server/utils/generateUtils.ts b/utilities/project-factory/src/server/utils/generateUtils.ts index 430ea5963d4..e6b7ee59e40 100644 --- a/utilities/project-factory/src/server/utils/generateUtils.ts +++ b/utilities/project-factory/src/server/utils/generateUtils.ts @@ -14,6 +14,7 @@ function extractProperties(obj: any) { } function areBoundariesSame(existingBoundaries: any, currentBoundaries: any) { + if (!existingBoundaries || !currentBoundaries) return false; if (existingBoundaries.length !== currentBoundaries.length) return false; const existingSetOfBoundaries = new Set(existingBoundaries.map((exboundary: any) => JSON.stringify(extractProperties(exboundary)))); const currentSetOfBoundaries = new Set(currentBoundaries.map((currboundary: any) => JSON.stringify(extractProperties(currboundary)))); @@ -81,4 +82,4 @@ async function callGenerate(request: any, type: any) { -export { callGenerateIfBoundariesDiffer, callGenerate } \ No newline at end of file +export { callGenerateIfBoundariesDiffer, callGenerate } diff --git a/utilities/project-factory/src/server/utils/targetUtils.ts b/utilities/project-factory/src/server/utils/targetUtils.ts index 4efca24623f..0ebc47aadb1 100644 --- a/utilities/project-factory/src/server/utils/targetUtils.ts +++ b/utilities/project-factory/src/server/utils/targetUtils.ts @@ -16,6 +16,7 @@ async function generateDynamicTargetHeaders(request: any, campaignObject: any, l } else { headerColumnsAfterHierarchy = await getConfigurableColumnHeadersBasedOnCampaignType(request); + headerColumnsAfterHierarchy.shift(); } return headerColumnsAfterHierarchy; }