2 回答

TA貢獻1851條經(jīng)驗 獲得超3個贊
設(shè)置它的一種方法是將其存儲在基于message_id. 例如,這里是一些示例服務(wù)器代碼:
def callback(message):
# Message has been received by the Server/Subscriber
cursor.execute('INSERT IGNORE INTO pubsub (id, message, received) VALUES (%s, %s, NOW())', (message.message_id, message.data))
connection.commit()
# Message is processed by the Server/Subscriber
data_obj = loads(message.data)
_process(data_obj)
# Message has finished being processed by the Server/Subscriber
cursor.execute('UPDATE pubsub SET completed=NOW() WHERE id=%s', (message.message_id,))
connection.commit()
message.ack()
客戶端可以id通過訪問future.result(),因此可以輕松查詢以查看狀態(tài)。如果在單獨的進程中查看狀態(tài)(例如,如果 100 個長時間運行的進程正在運行并且我們想要跟蹤哪些已完成),這會特別有用。
添加回答
舉報