I have an initial event with some key.
I want to understand, if there are no events with the same key happened within fixed time interval(let's assume 60 seconds) after initial event and do some actions in this case immediately.
The first thought was to create KSQL
table with WINDOW SESSION
, something like:
SELECT
COUNT(*) as total,
COLLECT_LIST(ts) AS ts_list,
field1 as f1,
field2 as f2,
WINDOWEND as window_end,
WINDOWSTART as window_start
FROM events_source_topic
WINDOW SESSION (60 SECONDS)
WHERE field3 = 'some_condition_string'
GROUP BY
field1,
field2;
As a result I receive 2 messages in case if there are 2 events in window, because by default it reacts on every change of a window. I'm not interested in intermediate states of a window, so I've tried to use EMIT FINAL
like
SELECT
COUNT(*) as total,
COLLECT_LIST(ts) AS ts_list,
field1 as f1,
field2 as f2,
WINDOWEND as window_end,
WINDOWSTART as window_start
FROM source_topic
WINDOW SESSION (60 SECONDS)
WHERE field3 = 'some_condition_string'
GROUP BY
field1,
field2
EMIT FINAL;
According to the documentation, I should get only one message when window was closed and I can analyse how many events were inside. Unfortunately I don't get this message immediately right after 60 seconds from the last event, but get it only after the first event for the new window(for the same partition I guess).
- I've found similar questions here and here and it seems that it was impossible to get message right after inactivity period of window, because
KSQL
windows are event-based, but not time-based. They were answered 2 years ago, are there any changes with it since then? - Is there any other way to get an event after fixed period of time from the initial event, without organising scheduled/postponed calls on the client?
I've also tried to decrease GRACE PERIOD
of a window, but it doesn't work as well