summaryrefslogtreecommitdiff
path: root/test/plugin/example_plugin_message.lua
blob: e6d8967df04c54364ae2a88aeda8d1fd95ad4506 (plain)
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
function plugin_ctx_new(sess, plug_env, sess_context)
    -- print("now create new ctx example message, plugin id", plug_env.id)
end

function plugin_ctx_free(sess, sess_context, plug_env)
    -- print("now begin to free ctx context example message")
end

function on_message(sess, topic_id, msg, sess_context, env)
    -- print("message call on message function, id", topic_id)
    print("get message is", topic_id, msg.data)
end

function plugin_load(stellar, plug_env)
    plug_env.st = stellar
    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 = 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, "LUA_TOPIC_SESSION_STAT", nil, nil)
        print("create topic is", test_topic_id)
    end
    session_mq.subscribe_topic(stellar, test_topic_id, on_message, plug_env.id)
end

function plugin_unload(plug_env)
    print("now unload lua plugin example message")
    print("plugin env data is", plug_env.data)
end