队列表mysql,什么是在mysql中实现消息队列表的最佳方法
這可能是我第十次執行這樣的事情,而且我從未對我提出的解決方案感到滿意。
使用mysql表而不是“正確”消息傳遞系統的原因是有吸引力的,主要是因為大多數應用程序已經在使用一些關系數據庫來使用其他的東西(這往往是我一直在做的大部分的mysql),而很少的應用程序使用消息系統。此外 – 關系數據庫具有非常強的ACID屬性,而消息傳遞系統通常不會。
第一個想法是使用:
create table jobs(
id auto_increment not null primary key,
message text not null,
process_id varbinary(255) null default null,
key jobs_key(process_id)
);
然后排隊看起來像這樣:
insert into jobs(message) values('blah blah');
并且出隊看起來像這樣:
begin;
select * from jobs where process_id is null order by id asc limit 1;
update jobs set process_id = ? where id = ?; -- whatever i just got
commit;
-- return (id, message) to application, cleanup after done
表和排隊看起來不錯,但出隊有點麻煩我。回滾的可能性有多大?還是被封鎖?我應該用什么鑰匙來做O(1)?
還是有什么更好的解決方案,我在做什么?
總結
以上是生活随笔為你收集整理的队列表mysql,什么是在mysql中实现消息队列表的最佳方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python转义符个数,python(五
- 下一篇: oracle 客户端访问数据库,ORAC