Vincenzo Lombardo created NIFI-16650:
----------------------------------------

             Summary: ConsumeIMAP marks messages as SEEN or DELETED before 
FlowFiles are committed
                 Key: NIFI-16650
                 URL: https://issues.apache.org/jira/browse/NIFI-16650
             Project: Apache NiFi
          Issue Type: Bug
            Reporter: Vincenzo Lombardo
            Assignee: Vincenzo Lombardo


ConsumeIMAP relies on Spring Integration ImapMailReceiver.receive(), which 
applies \Seen (Mark Messages as
Read) and \Deleted (Delete Messages) to the fetched messages before returning 
them, and closes the folder
(expunging when deleting) before AbstractEmailProcessor writes any FlowFile.

AbstractEmailProcessor then keeps the received messages in an in-memory queue 
of up to Fetch Size messages
and transfers only one message per trigger. As a result the processor provides 
at-most-once delivery:

- If NiFi stops abnormally, restarts, or the node fails while the queue is not 
empty, the queued messages
  are already flagged or deleted on the server but were never transferred.
- If writing a message to a FlowFile fails, the exception propagates out of 
onTrigger(), the session rolls
  back, and the message, already removed from the queue and flagged on the 
server, is lost.

With Mark Messages as Read = false, the Spring receiver flags each fetched 
message with the user flag
"spring-integration-mail-adapter" (or \Flagged as fallback) when the server 
does not support RECENT.
That flag is also applied before commit.

Proposal for discussion:
- Disable flag handling in the Spring receiver 
(shouldMarkMessagesAsRead/shouldDeleteMessages false,
  autoCloseFolder false) and apply \Seen / \Deleted / expunge in the 
ProcessSession.commitAsync() success
  callback, so flags are only set for committed FlowFiles (at-least-once)
- Transfer all messages returned by a receive() call in the same trigger, 
removing the in-memory queue
- Decide how to keep the current Mark Messages as Read = false behavior (avoid 
re-reading the same messages):
  apply the same marker flag after commit

Open question for maintainers: whether at-least-once (possible duplicates after 
a failed flag update) is
the preferred semantic over the current at-most-once behavior.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to