I'm looking for a queue data structure which supports the following:
Given items with (ID, value) it should contain only the newest values for a given ID. E.g. if there is an item with ID 5 and value "a" in the queue not yet consumed and the new item with ID 5 and value "b" is added to the queue, the old item with value "a" must be discarded.
items must be rate limited per second. E.g. at most one item with ID 6 must be available for consuming
the data structure is thread safe as it will have multiple consumers from different threads
the data structure must support high throughput ideally 1 000 000 incoming messages per second
I have tried a combination of concurrent hash map with a queue and wonder if there might be a better solution