If the consumer is running in the main thread itself, we invoke the wakeup() method on the consumer object in the shutdown hook of the runtime. The code widget below demonstrates how to implement the shutdown hook for a consumer that runs in the main thread. Read through the comments to understand the example.