• 插件开发
    • Server Plugin
    • Client Plugin

    插件开发

    rpcx为服务器和客户端定义了几个插件接口,在一些处理点上可以调用插件。

    Server Plugin

    示例: trace

    go doc

    1. type PostConnAcceptPlugin
    2. type PostConnAcceptPlugin interface {
    3. HandleConnAccept(net.Conn) (net.Conn, bool)
    4. }
    5. type PostReadRequestPlugin
    6. type PostReadRequestPlugin interface {
    7. PostReadRequest(ctx context.Context, r *protocol.Message, e error) error
    8. }
    9. PostReadRequestPlugin represents .
    10. type PostWriteResponsePlugin
    11. type PostWriteResponsePlugin interface {
    12. PostWriteResponse(context.Context, *protocol.Message, *protocol.Message, error) error
    13. }
    14. PostWriteResponsePlugin represents .
    15. type PreReadRequestPlugin
    16. type PreReadRequestPlugin interface {
    17. PreReadRequest(ctx context.Context) error
    18. }
    19. PreReadRequestPlugin represents .
    20. type PreWriteResponsePlugin
    21. type PreWriteResponsePlugin interface {
    22. PreWriteResponse(context.Context, *protocol.Message) error
    23. }
    24. PreWriteResponsePlugin represents .

    Client Plugin

    go doc

    1. type PluginContainer
    2. type PluginContainer interface {
    3. Add(plugin Plugin)
    4. Remove(plugin Plugin)
    5. All() []Plugin
    6. DoPreCall(ctx context.Context, servicePath, serviceMethod string, args interface{}) error
    7. DoPostCall(ctx context.Context, servicePath, serviceMethod string, args interface{}, reply interface{}, err error) error
    8. }
    9. type PostCallPlugin
    10. type PostCallPlugin interface {
    11. DoPostCall(ctx context.Context, servicePath, serviceMethod string, args interface{}, reply interface{}, err error) error
    12. }
    13. PostCallPlugin is invoked after the client calls a server.
    14. type PreCallPlugin
    15. type PreCallPlugin interface {
    16. DoPreCall(ctx context.Context, servicePath, serviceMethod string, args interface{}) error
    17. }
    18. PreCallPlugin is invoked before the client calls a server.