Sent messages are deleted individually after a crash
[demos/kafka/outbox] / delivery / src / main / java / de / juplo / kafka / outbox / delivery / OutboxRepository.java
index d6c814d..9dee55d 100644 (file)
@@ -8,6 +8,7 @@ import org.springframework.stereotype.Repository;
 import java.sql.Timestamp;
 import java.time.ZonedDateTime;
 import java.util.List;
+import java.util.Set;
 
 
 @Repository
@@ -19,7 +20,7 @@ public class OutboxRepository
   private static final String SQL_UPDATE =
       "INSERT INTO outbox (key, value, issued) VALUES (:key, :value, :issued)";
   private static final String SQL_DELETE =
-      "DELETE FROM outbox WHERE id <= :id";
+      "DELETE FROM outbox WHERE id IN (:ids)";
 
   private final NamedParameterJdbcTemplate jdbcTemplate;
 
@@ -33,10 +34,12 @@ public class OutboxRepository
     jdbcTemplate.update(SQL_UPDATE, parameters);
   }
 
-  public int delete(Long id)
+  public int delete(Set<Long> ids)
   {
+    if (ids == null || ids.isEmpty())
+      return 0;
     MapSqlParameterSource parameters = new MapSqlParameterSource();
-    parameters.addValue("id", id);
+    parameters.addValue("ids", ids);
     return jdbcTemplate.update(SQL_DELETE, parameters);
   }