Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Consumers are always invoked from the consuming connection's IO-Thread whereas the Queue might be invoked from different threads (producing connection's IO-Thread, Housekeeping thread for held or TTLed messages, a consuming connection's IO-Thread in case for message reject).

Therefore, the interfaces between Consumers and the Queue MUST be thread-safe and SHOULD be lock free.

Interfaces Between Consumers and Queues

These are the interfaces between Consumers and Queues and the scenarios when they are called.

  • AbstractQueue#setNotifyWorkDesired
    Called by the Consumer to notify the Queue whether it is interested in doing work or not.
    • FlowControl
    • Credit
    • TCP backpressure
  • QueueConsumer#notifyWork
    Called by the Queue to notify the Consumer that there is potentially work available.
    • Consumer becomes Interested
    • A new message arrives
    • A previously unavailable (acquired, held, blocked by message grouping) message becomes available
    • A notified consumer did not do the work we expected it to do we need to notify someone else 
    • A high priority consumer becomes uninterested and thus allows a low priority consumer to consume messages
  • AbstractQueue#deliverSingleMessage
    Called by the Consumer to get a message from the Queue.
    • A consumer was notified and now tries to pull a message of a queue

...


QueueConsumerManager internals

The QueueConsumerManager (QCM for short) keeps track of the state of Consumers from the perspective of the Queue. It shares the decides which Consumer to notify of work with the Queue. To do this in a performant way it maintains a number of lists and moves Consumers between those lists to indicate state change. The lists it maintains are:

...

Typically we want these lists to be thread-safe and give us O(1) access/deletion if we know the element and O(1) size information. Unfortunately there does not exist a is no data structure in the Java standard library with those characteristics which is why they are based on our own data structure QueueConsumerNodeList.

...