All Downloads are FREE. Search and download functionalities are using the official Maven repository.

kafka.entity.changelog.topic.TopicNotificationService Maven / Gradle / Ivy

package kafka.entity.changelog.topic;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import kafka.entity.changelog.notification.NotificationProvider;
import kafka.entity.changelog.schema.Topic;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

class TopicNotificationService {
  static final Logger LOG = LoggerFactory.getLogger(TopicNotificationService.class);

  final NotificationProvider notificationProvider;

  TopicNotificationService(NotificationProvider notificationProvider) {
    this.notificationProvider = notificationProvider;
  }

  void send(Topic.Event event) {
    String message = null;
    if (event.hasCreationEvent()) {
      if (event.getCreationEvent().hasTopicCreated()) {
        message =
            String.format(
                "Topic %s has been created (Partitions=%d Replication-factor=%d) by %s (source: %s). Found at %s",
                event.getCreationEvent().getTopicCreated().getName(),
                event.getCreationEvent().getTopicCreated().getPartitions(),
                event.getCreationEvent().getTopicCreated().getReplicationFactor(),
                event.getUsername(),
                event.getSource(),
                LocalDateTime.ofInstant(
                    Instant.ofEpochMilli(event.getTimestamp()),
                    ZoneId.systemDefault()).format(DateTimeFormatter.ISO_DATE_TIME));
      }
      if (event.getCreationEvent().hasTopicDeleted()) {
        message =
            String.format("Topic %s has been deleted by %s (source: %s). Found at %s",
                event.getCreationEvent().getTopicDeleted().getName(),
                event.getUsername(),
                event.getSource(),
                LocalDateTime.ofInstant(
                    Instant.ofEpochMilli(event.getTimestamp()),
                    ZoneId.systemDefault()).format(DateTimeFormatter.ISO_DATE_TIME));
      }
    }
    if (message != null) {
      notificationProvider.send(message);
    } else {
      LOG.warn("Event type not considered for notification");
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy