vigneshio commented on code in PR #4923:
URL: https://github.com/apache/polaris/pull/4923#discussion_r3493759651


##########
extensions/events/kafka/src/main/java/org/apache/polaris/extensions/events/kafka/KafkaEventListener.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.polaris.extensions.events.kafka;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.smallrye.common.annotation.Identifier;
+import jakarta.annotation.PostConstruct;
+import jakarta.annotation.PreDestroy;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.UUID;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.rest.requests.RenameTableRequest;
+import org.apache.kafka.clients.producer.KafkaProducer;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.kafka.common.serialization.StringSerializer;
+import org.apache.kafka.common.serialization.UUIDSerializer;
+import org.apache.polaris.service.events.EventAttributes;
+import org.apache.polaris.service.events.PolarisEvent;
+import org.apache.polaris.service.events.listeners.PolarisEventListener;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** Event Listener that pushes Polaris events to Kafka. */
+@ApplicationScoped
+@Identifier("kafka")
+public class KafkaEventListener implements PolarisEventListener {
+
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(KafkaEventListener.class);
+  private KafkaProducer<UUID, String> producer;
+  private final String topic;
+  private final boolean synchronousMode;
+  private final ObjectMapper objectMapper;
+  private final Map<String, String> kafkaProperties;
+
+  @Inject
+  public KafkaEventListener(
+      KafkaEventListenerConfiguration configuration, ObjectMapper 
objectMapper) {
+    this.synchronousMode = configuration.synchronousMode();
+    this.topic = configuration.topic();
+    this.objectMapper = objectMapper;
+    this.kafkaProperties = new HashMap<>(configuration.properties());
+  }
+
+  @PostConstruct
+  void start() {
+    LOGGER.debug("Starting KafkaEventListener.");
+    Properties props = new Properties();
+    props.putAll(this.kafkaProperties);
+    props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, 
UUIDSerializer.class.getName());
+    props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, 
StringSerializer.class.getName());
+    this.producer = new KafkaProducer<>(props);
+  }
+
+  @PreDestroy
+  void shutdown() {
+    if (producer != null) {
+      producer.close();

Review Comment:
   One thing on shutdown - in @PreDestroy you're calling producer.close() 
without a timeout. If the broker is down or slow, this can block for a very 
long time (basically forever). Using `producer.close(Duration.ofSeconds(10))` 
would be safer, especially in container environments where shutdown time 
matters... WDYT ? 
   
   There are no tests added for the listener. The other event listeners have 
tests, so it would be good to have some coverage here too.



##########
runtime/defaults/src/main/resources/application.properties:
##########
@@ -179,6 +179,12 @@ polaris.file-io.type=default
 # quarkus.otel.logs.enabled=true
 # quarkus.otel.exporter.otlp.endpoint=http://otlp-collector:4317
 
+# Kafka event listener settigs
+# polaris.event-listener.type=kafka

Review Comment:
   The config example still uses the old polaris.event-listener.type=kafka. 
Since 1.5 we moved to `polaris.event-listener.types` (plural) to support 
multiple listeners. The OpenTelemetry config in the same file already uses the 
new format, so it would be good to align this one too.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to