From 0ad36763fed3806e94ef2a48e5436b4d91202e91 Mon Sep 17 00:00:00 2001 From: Jade Carino Date: Fri, 28 Jun 2024 21:34:21 +0100 Subject: [PATCH] Move class loader line for Kafka classes at runtime Signed-off-by: Jade Carino --- .../dev/galasa/events/kafka/internal/KafkaEventProducer.java | 2 -- .../events/kafka/internal/KafkaEventProducerFactory.java | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/galasa-extensions-parent/dev.galasa.events.kafka/src/main/java/dev/galasa/events/kafka/internal/KafkaEventProducer.java b/galasa-extensions-parent/dev.galasa.events.kafka/src/main/java/dev/galasa/events/kafka/internal/KafkaEventProducer.java index e866e912..8a90cd6b 100644 --- a/galasa-extensions-parent/dev.galasa.events.kafka/src/main/java/dev/galasa/events/kafka/internal/KafkaEventProducer.java +++ b/galasa-extensions-parent/dev.galasa.events.kafka/src/main/java/dev/galasa/events/kafka/internal/KafkaEventProducer.java @@ -21,8 +21,6 @@ public class KafkaEventProducer implements IEventProducer { public KafkaEventProducer(Properties properties, String topic) { - Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); - KafkaProducer producer = new KafkaProducer(properties); this.producer = producer; diff --git a/galasa-extensions-parent/dev.galasa.events.kafka/src/main/java/dev/galasa/events/kafka/internal/KafkaEventProducerFactory.java b/galasa-extensions-parent/dev.galasa.events.kafka/src/main/java/dev/galasa/events/kafka/internal/KafkaEventProducerFactory.java index 8c2e3a33..92bef510 100644 --- a/galasa-extensions-parent/dev.galasa.events.kafka/src/main/java/dev/galasa/events/kafka/internal/KafkaEventProducerFactory.java +++ b/galasa-extensions-parent/dev.galasa.events.kafka/src/main/java/dev/galasa/events/kafka/internal/KafkaEventProducerFactory.java @@ -36,6 +36,9 @@ public Properties createProducerConfig(IConfigurationPropertyStoreService cps, S try { String bootstrapServers = cps.getProperty("bootstrap", "servers"); + // Needed to get the Kafka classes at runtime + Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); + properties.put("bootstrap.servers", bootstrapServers); properties.put("topic", topic); properties.put("key.serializer", StringSerializer.class.getName());