hashicorp / go-plugin

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

How can sub plugins proactively initiate requests to the main application? #253

Closed heaxo closed 1 year ago

heaxo commented 1 year ago

How can sub plugins proactively initiate requests to the main application? The example I see is the main application plugin. NewClient, which calls the methods of the sub plugin through the client. How to call the methods of the main application in the sub plugin

tomhjp commented 1 year ago

Check out the bidirectional example: https://github.com/hashicorp/go-plugin/tree/main/examples/bidirectional

The main application exposes a gRPC service (AddHelper) to the plugin and the plugin can call that service's methods. In the example it only calls that method in response to plugin RPCs, but a long lived plugin can keep a connection to the service and call it whenever it likes. For example, Vault exposes a storage service to plugins and some plugins use that to access storage from background processing routines.

heaxo commented 1 year ago

@tomhjp Thanks