Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #244 from galasa-dev/add-logging-to-kafka
Browse files Browse the repository at this point in the history
Add logging to Kafka events service for demo purposes
  • Loading branch information
KirbyKatcher authored Jul 3, 2024
2 parents a41e75c + 6c673b8 commit 4f89833
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@
import java.util.HashMap;
import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class KafkaEventsService implements IEventsService {

private final Log logger = LogFactory.getLog(getClass());

private IConfigurationPropertyStoreService cps;

private IEventProducerFactory producerFactory;
Expand Down Expand Up @@ -47,11 +52,14 @@ public void produceEvent(String topic, IEvent event) throws EventsException {
producer = producers.get(topic);

if (producer == null) {
logger.info("Creating a new producer as one does not exist for the topic " + topic);

Properties properties = this.producerFactory.createProducerConfig(cps, topic);

producer = this.producerFactory.createProducer(properties, topic);
producers.put(topic, producer);
} else {
logger.info("Using the cached producer for the topic " + topic);
}
}

Expand All @@ -62,7 +70,7 @@ public void produceEvent(String topic, IEvent event) throws EventsException {

@Override
public void shutdown() {
// Shut down all cached EventProducers
logger.info("Shutting down all cached producers");
for (Map.Entry<String, IEventProducer> entry : producers.entrySet()) {
entry.getValue().close();
}
Expand Down

0 comments on commit 4f89833

Please sign in to comment.