diff options
| author | niubinghui <[email protected]> | 2024-09-06 18:57:29 +0800 |
|---|---|---|
| committer | niubinghui <[email protected]> | 2024-09-06 18:57:29 +0800 |
| commit | 1d9e18762499e652af25b943001bc4fc307f989d (patch) | |
| tree | 62aae0ea410a4fffa7cc26566a7b3eadb458a3d2 /example/plugin | |
| parent | 425cd807d3762dad049419e1636f45c3a67bb2b1 (diff) | |
【修改】基础功能验证
Diffstat (limited to 'example/plugin')
| -rw-r--r-- | example/plugin/example_plugin_message.lua | 8 | ||||
| -rw-r--r-- | example/plugin/example_plugin_regist.lua | 2 | ||||
| -rw-r--r-- | example/plugin/example_plugin_topic.lua | 30 |
3 files changed, 22 insertions, 18 deletions
diff --git a/example/plugin/example_plugin_message.lua b/example/plugin/example_plugin_message.lua index 3d1f52b..6515bdc 100644 --- a/example/plugin/example_plugin_message.lua +++ b/example/plugin/example_plugin_message.lua @@ -8,7 +8,7 @@ end function on_message(sess, topic_id, msg, sess_context, env) -- print("message call on message function, id", topic_id) - -- print("message is", msg.data) + print("message is", msg.data) end function plugin_load(stellar, plug_env) @@ -16,12 +16,12 @@ function plugin_load(stellar, plug_env) print("this example aims to test topic functions") plug_env.st = stellar - plug_env.id = plugin_manage.register(stellar, plugin_ctx_new, plugin_ctx_free, plug_env) + plug_env.id = session_plugin.register(stellar, plugin_ctx_new, plugin_ctx_free, plug_env) plug_env.data = "this is message example plug env data" --[[ 订阅TOPIC_SESSION_STAT, 并完成函数注册 ]] - test_topic_id = message.gettopicid(stellar, "TOPIC_SESSION_STAT") - message.subscribetopic(stellar, test_topic_id, on_message, plug_env.id) + test_topic_id = session_mq.get_topic_id(stellar, "TOPIC_SESSION_STAT") + session_mq.subscribe_topic(stellar, test_topic_id, on_message, plug_env.id) end function plugin_unload(plug_env) diff --git a/example/plugin/example_plugin_regist.lua b/example/plugin/example_plugin_regist.lua index 4cc3cd3..552e4af 100644 --- a/example/plugin/example_plugin_regist.lua +++ b/example/plugin/example_plugin_regist.lua @@ -14,7 +14,7 @@ function plugin_load(stellar, plug_env) print("this example aims to test regist function") plug_env.data = "my example regist plugin env" --[[ 由于未订阅消息, 注册函数应该永远不会触发 ]] - plug_env.id = plugin_manage.register(stellar, plugin_ctx_new, plugin_ctx_free, plug_env) + plug_env.id = session_plugin.register(stellar, plugin_ctx_new, plugin_ctx_free, plug_env) print("plugin env data is", plug_env.data) print("after regist, plugin id is", plug_env.id) end diff --git a/example/plugin/example_plugin_topic.lua b/example/plugin/example_plugin_topic.lua index a596cc6..44f08dd 100644 --- a/example/plugin/example_plugin_topic.lua +++ b/example/plugin/example_plugin_topic.lua @@ -1,21 +1,24 @@ function plugin_ctx_new(sess, plug_env, sess_context) - -- print("now create new ctx example topic, plugin id", plug_env.id) + print("now create new ctx example topic, plugin id", plug_env.id) + sess_context.count = 0 msg = {} msg.data = "this is message" - message.publishmessage(sess, plug_env.topic_id, msg) + session_mq.publish_message(sess, plug_env.topic_id, msg) end function plugin_ctx_free(sess, sess_context, plug_env) - -- print("now begin to free ctx context example topic") + print("now begin to free ctx context example topic") + print(sess_context.count) end function on_message(sess, topic_id, msg, sess_context, env) - -- print("topic call on message function, id", topic_id) + sess_context.count = sess_context.count + 1 + print("topic call on message function, id", topic_id) end function free_message(sess, msg, private_env) - -- print("message need to free is", msg.data) - -- print("env id is ", private_env.id) + print("message need to free is", msg.data) + print("env id is ", private_env.id) end function plugin_load(stellar, plug_env) @@ -23,26 +26,27 @@ function plugin_load(stellar, plug_env) print("this example aims to test topic functions") plug_env.st = stellar - plug_env.id = plugin_manage.register(stellar, plugin_ctx_new, plugin_ctx_free, plug_env) + plug_env.id = session_plugin.register(stellar, plugin_ctx_new, plugin_ctx_free, plug_env) plug_env.data = "this is topic example plug env data" --[[ 获取TCP topic, 并完成订阅 ]] - tcp_topic_id = message.gettopicid(stellar, "TCP") + tcp_topic_id = session_mq.get_topic_id(stellar, "TCP") print("get TCP topic id is", tcp_topic_id) - message.subscribetopic(stellar, tcp_topic_id, on_message, plug_env.id) + session_mq.subscribe_topic(stellar, tcp_topic_id, on_message, 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 = message.gettopicid(stellar, "TOPIC_SESSION_STAT") + test_topic_id = session_mq.get_topic_id(stellar, "TOPIC_SESSION_STAT") if (test_topic_id < 0) then --[[ 该消息未创建, 创建该topic ]] - test_topic_id = message.createtopic(stellar, "TOPIC_SESSION_STAT", free_message, msg_private_table) + test_topic_id = session_mq.create_topic(stellar, "TOPIC_SESSION_STAT", free_message, msg_private_table) print("create topic is", test_topic_id) else --[[ 如果该消息已经注册, 更新其注册函数 ]] - message.updatetopic(stellar, test_topic_id, free_message, msg_private_table) + session_mq.update_topic(stellar, test_topic_id, free_message, msg_private_table) print("topic already created, id is", test_topic_id) end plug_env.tcp_topic_id = tcp_topic_id @@ -53,5 +57,5 @@ function plugin_unload(plug_env) print("now unload lua plugin example topic") print("plugin env data is", plug_env.data) print("now destory topic id is", plug_env.topic_id) - message.destorytopic(plug_env.st, plug_env.topic_id) + session_mq.destory_topic(plug_env.st, plug_env.topic_id) end
\ No newline at end of file |
