Complete the code to insert an event into the outbox table within the same transaction.
BEGIN TRANSACTION; INSERT INTO orders (id, status) VALUES (123, 'created'); INSERT INTO outbox (event_type, payload) VALUES ('OrderCreated', [1]); COMMIT;
The event payload must be a JSON string representing the event data. Here, we insert a JSON string with the order ID.
Complete the code to select unprocessed events from the outbox for publishing.
SELECT id, event_type, payload FROM outbox WHERE processed = [1];We select events that have not been processed yet, so processed should be FALSE.
Fix the error in the code that marks an event as processed after publishing.
UPDATE outbox SET processed = [1] WHERE id = event_id;After publishing, the event should be marked as processed = TRUE.
Fill both blanks to implement a retry mechanism that selects events with less than 5 attempts and marks them as processing.
SELECT id FROM outbox WHERE processed = FALSE AND attempts [1] 5; UPDATE outbox SET processing = TRUE WHERE id = [2];
We select events with attempts less than 5 and update the processing flag for a specific event id.
Fill all three blanks to create a dictionary comprehension that maps event IDs to payloads for unprocessed events with attempts less than 3.
events = {event['id']: event[[1]] for event in events_list if event[[2]] [3] 3 and event['processed'] == False}The comprehension maps event IDs to their payloads, filters events with attempts less than 3 and not processed.