Prototype: MessageQueue.publish(messageId,payload) returns true once per lifetime ID, including IDs already consumed. consume destructively returns oldest {id,payload} or null. Empty IDs/payloads valid; no replacement.

Final: MessageBroker(maxAttempts=2) requires positive safe integer, counting initial delivery. publish retains lifetime-unique immutable messages. subscribe(groupId) creates progress from oldest message, duplicate false preserving position. poll returns {id,payload,attempt}, null for unknown/caught-up, and repeats current attempt without increment. ack accepts only current matching in-flight delivery, returns bool, advances/reset attempt. nack returns null if invalid, retry below limit without advancing, or dead-letter at limit and appends {id,payload,attempts} to that group then advances. Ack/nack between rejection and redelivery is invalid. deadLetters returns fresh nondraining nested snapshots or [] for unknown. Groups are independent; empty string group IDs valid. No wall clock, timeout, or deletion.

Every class is exported by name from exercise.mjs. Keep instances independent. Unless explicitly documented otherwise, input values have the stated collection/string types and do not contain null elements. Invalid calls preserve state; validate before mutation. Return fresh mutable snapshots unless stated otherwise.

Drag or use the arrow keys to resize. Home collapses the question; End collapses the editor. Enter or double-click resets the split.
Loading editor…
No results yet.

Complete the starter code, then run the checks.
Results and errors will appear here.