Savonitar commented on code in PR #130:
URL: 
https://github.com/apache/flink-connector-pulsar/pull/130#discussion_r4379426666


##########
flink-connector-pulsar/src/main/java/org/apache/flink/connector/pulsar/sink/writer/PulsarWriter.java:
##########
@@ -167,18 +178,38 @@ public void write(IN element, Context context) throws 
IOException, InterruptedEx
             CompletableFuture<MessageId> future = builder.sendAsync();
             future.whenComplete(
                     (id, ex) -> {
-                        pendingMessages.decrementAndGet();
-                        if (ex != null) {
-                            mailboxExecutor.execute(
-                                    () -> throwSendingException(topic, ex),
-                                    "Failed to send data to Pulsar");
-                        } else {
-                            LOG.debug("Sent message to Pulsar {} with message 
id {}", topic, id);
+                        try {
+                            if (ex != null) {
+                                mailboxExecutor.execute(
+                                        () -> throwSendingException(topic, ex),
+                                        "Failed to send data to Pulsar");
+                            } else {
+                                recordLatestMessageId(topic, id);
+                                LOG.debug(
+                                        "Sent message to Pulsar {} with 
message id {}", topic, id);
+                            }
+                        } finally {
+                            pendingMessages.decrementAndGet();
                         }
                     });
         }
     }
 
+    private void recordLatestMessageId(String topic, MessageId messageId) {
+        if (deliveryGuarantee != DeliveryGuarantee.EXACTLY_ONCE) {
+            return;
+        }
+
+        // Producer sends return MessageIdImpl subclasses, which implement 
MessageIdAdv.
+        MessageIdAdv messageIdAdv = (MessageIdAdv) messageId;
+        latestPublishedMessages.compute(
+                topic,
+                (ignored, current) ->
+                        current == null || messageIdAdv.compareTo(current) > 0

Review Comment:
   https://github.com/apache/flink-connector-pulsar/pull/133



-- 
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