hashicorp / go-plugin

Golang plugin system over RPC.
Mozilla Public License 2.0
5.25k stars 450 forks source link

question: How to do multi request and multi response in a single plugin process ? #221

Closed ahfuzhang closed 1 year ago

ahfuzhang commented 1 year ago

see example code blow. I don't known how to create many client to do rcp call parallel.

    // Connect via RPC
    rpcClient, err := client.Client() // I guess: fork a new process when call this  func
    if err != nil {
        fmt.Println("Error:", err.Error())
        os.Exit(1)
    }

    // Request the plugin
    raw, err := rpcClient.Dispense("kv_grpc") // If I need many client, can I use this func ?
    if err != nil {
        fmt.Println("Error:", err.Error())
        os.Exit(1)
    }

    // We should have a KV store now! This feels like a normal interface
    // implementation but is in fact over an RPC connection.
    kv := raw.(shared.KV) //  type KV interface
        result, err := kv.Get("xxxxx")

Thanks.

fairclothjm commented 1 year ago

@ahfuzhang Hi

If you want to reuse the same plugin process you will want to use the same client. What you will need to do to support parallel requests to the same plugin process is ensure your client and server implementations can handle the requests appropriately for your use case.

ahfuzhang commented 1 year ago

@ahfuzhang Hi

If you want to reuse the same plugin process you will want to use the same client. What you will need to do to support parallel requests to the same plugin process is ensure your client and server implementations can handle the requests appropriately for your use case.

thanks. use kv instance to do parallel request is ok.