Skip to content
This repository has been archived by the owner on Jun 10, 2022. It is now read-only.

Commit

Permalink
add example
Browse files Browse the repository at this point in the history
  • Loading branch information
nmred committed Apr 7, 2017
1 parent 40d58ac commit 5d5b361
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
3 changes: 2 additions & 1 deletion conf/system.ini
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ accessLogDir=logs/
accesslogRollSize=52428800
defaultController=index
defaultAction=index
scriptName=lua/http.lua
scriptName=http.lua

[head]
host=0.0.0.0
Expand All @@ -47,6 +47,7 @@ serverName=head-server
[kafkac_out]
;是否是 v0.9.x 新协议获取
isNewConsumerOut=yes
; 支持同时消费多个 topic, 多个用逗号分隔
topicNameOut=test,admid_mark
groupIdOut=test_group_id
brokerListOut=10.13.4.161:9192,10.13.4.160:9192
Expand Down
23 changes: 23 additions & 0 deletions example/dusty.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--
--
-- 该脚本实现将 kafka 中的数据落地到文件中,并且统计落地消息数
--
--
local obj = aidp.message.get()
local filename = os.date('%Y-%m-%d-%H') .. '.log'
local files = {};
local storage = aidp.storage()
for k,v in pairs(obj) do
if #v == 3 then
if files[v[2]] == nil then
files[v[2]] = io.open(v[2]..filename, 'a+');
files[v[2]]:setvbuf('full')
end
files[v[2]]:write(v[3]..'\n')
storage:incr(v[2] .. ':message_size', 1)
end
end
for k,v in pairs(files) do
v:flush()
v:close()
end
42 changes: 42 additions & 0 deletions example/http.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

---
-- @function: 打印table的内容,递归
-- @param: tbl 要打印的table
-- @param: level 递归的层数,默认不用传值进来
-- @param: filteDefault 是否过滤打印构造函数,默认为是
-- @return: return
function PrintTable( tbl , level, filteDefault)
local msg = ""
filteDefault = filteDefault or true --默认过滤关键字(DeleteMe, _class_type)
level = level or 1
local indent_str = ""
for i = 1, level do
indent_str = indent_str.." "
end

print(indent_str .. "{")
for k,v in pairs(tbl) do
if filteDefault then
if k ~= "_class_type" and k ~= "DeleteMe" then
local item_str = string.format("%s%s = %s", indent_str .. " ",tostring(k), tostring(v))
print(item_str)
if type(v) == "table" then
PrintTable(v, level + 1)
end
end
else
local item_str = string.format("%s%s = %s", indent_str .. " ",tostring(k), tostring(v))
print(item_str)
if type(v) == "table" then
PrintTable(v, level + 1)
end
end
end
print(indent_str .. "}")
end

local request = aidp.http.request();
local topic_name = request:get_query('t')
local response = aidp.http.response();
local storage = aidp.storage()
response:set_content(topic_name .. ':message_size ' .. storage:get(topic_name .. ':message_size'));

0 comments on commit 5d5b361

Please sign in to comment.