這個案例的核心責任是說明 AMQP client 的 connection / channel 邊界跟執行緒模型緊密耦合。

觀察

從 Unicorn 切到 Puma 後遇到 ConnectionClosedError、根因是快取 Bunny channel 在多執行緒間共享。

判讀

AMQP channel 不應跨執行緒共用、改用 connection_pool gem 管理 channel pool。揭露 AMQP 不是 stateless HTTP-style client、channel 是 statefull 物件、多 thread 模型要特別處理。

對應大綱

RabbitMQ 進階主題:Prefetch + consumer 併發(client library 層的 connection / channel 邊界)。

下一步路由

RabbitMQ vendor 頁3.4 consumer 設計

引用源