【新增】
修改部分测试代码
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
function plugin_ctx_new(sess, plug_env, sess_context)
|
||||
print("now create new ctx example topic, plugin id", plug_env.id)
|
||||
sess_context.count = 0
|
||||
sess_context.payload_len = 0
|
||||
msg = {}
|
||||
msg.data = "this is message"
|
||||
session_mq.publish_message(sess, plug_env.topic_id, msg)
|
||||
@@ -8,17 +9,20 @@ end
|
||||
|
||||
function plugin_ctx_free(sess, sess_context, plug_env)
|
||||
print("now begin to free ctx context example topic")
|
||||
print(sess_context.count)
|
||||
print("total packet count is", sess_context.count)
|
||||
print("total paylaod length is", sess_context.payload_len)
|
||||
end
|
||||
|
||||
function on_message(sess, topic_id, msg, sess_context, env)
|
||||
function on_message_fn(sess, topic_id, msg, sess_context, env)
|
||||
sess_context.count = sess_context.count + 1
|
||||
print("topic call on message function, id", topic_id)
|
||||
-- print("topic call on message function, id", topic_id)
|
||||
payload, payload_len = session.get_payload(sess)
|
||||
sess_context.payload_len = sess_context.payload_len + payload_len
|
||||
end
|
||||
|
||||
function free_message(sess, msg, private_env)
|
||||
function free_message(sess, msg, msg_free_arg)
|
||||
print("message need to free is", msg.data)
|
||||
print("env id is ", private_env.id)
|
||||
print("env id is ", msg_free_arg.id)
|
||||
end
|
||||
|
||||
function plugin_load(stellar, plug_env)
|
||||
@@ -32,21 +36,21 @@ function plugin_load(stellar, plug_env)
|
||||
--[[ 获取TCP topic, 并完成订阅 ]]
|
||||
tcp_topic_id = session_mq.get_topic_id(stellar, "TCP")
|
||||
print("get TCP topic id is", tcp_topic_id)
|
||||
session_mq.subscribe_topic(stellar, tcp_topic_id, on_message, plug_env.id)
|
||||
session_mq.subscribe_topic(stellar, tcp_topic_id, on_message_fn, plug_env.id)
|
||||
plug_env.tcp_topic_id = tcp_topic_id
|
||||
|
||||
--[[ 创建TOPIC_SESSION_STAT, 并完成函数注册 ]]
|
||||
msg_private_table = {}
|
||||
msg_private_table.data = "this is example topic msg private data"
|
||||
test_topic_id = session_mq.get_topic_id(stellar, "TOPIC_SESSION_STAT")
|
||||
msg_free_arg = {}
|
||||
msg_free_arg.data = "this is example topic msg private data"
|
||||
test_topic_id = session_mq.get_topic_id(stellar, "LUA_TOPIC_SESSION_STAT")
|
||||
if (test_topic_id < 0)
|
||||
then
|
||||
--[[ 该消息未创建, 创建该topic ]]
|
||||
test_topic_id = session_mq.create_topic(stellar, "TOPIC_SESSION_STAT", free_message, msg_private_table)
|
||||
test_topic_id = session_mq.create_topic(stellar, "LUA_TOPIC_SESSION_STAT", free_message, msg_free_arg)
|
||||
print("create topic is", test_topic_id)
|
||||
else
|
||||
--[[ 如果该消息已经注册, 更新其注册函数 ]]
|
||||
session_mq.update_topic(stellar, test_topic_id, free_message, msg_private_table)
|
||||
session_mq.update_topic(stellar, test_topic_id, free_message, msg_free_arg)
|
||||
print("topic already created, id is", test_topic_id)
|
||||
end
|
||||
plug_env.tcp_topic_id = tcp_topic_id
|
||||
|
||||
Reference in New Issue
Block a user