forked from cfadmin-cn/cfadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_MQ.lua
More file actions
45 lines (36 loc) · 851 Bytes
/
test_MQ.lua
File metadata and controls
45 lines (36 loc) · 851 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
-- 基于redis的订阅与发布消息队列(同步处理)
local Timer = require "internal.Timer"
local MQ = require "MQ"
require "utils"
local rds = MQ:new {
host = 'localhost',
port = 6379,
type = 'redis'
}
print(rds:on('/test/*', function (msg)
var_dump(msg)
end))
Timer.at(1, function ( ... )
rds:emit("/test/admin", '{"code":100}')
end)
Timer.sleep(10)
print("停止消息队列监听与投递.")
rds:close()
-- 基于mqtt的订阅与发布消息队列(同步处理)
local Timer = require "internal.Timer"
local MQ = require "MQ"
require "utils"
local mqtt = MQ:new {
host = 'localhost',
port = 1883,
type = 'mqtt'
}
Timer.at(0.1, function ( ... )
mqtt:emit("/test/admin", '{"code":100}')
end)
print(mqtt:on('/test/*', function (msg)
var_dump(msg)
end))
Timer.sleep(10)
print("停止消息队列监听与投递.")
mqtt:close()