hashicorp / hashicorp/go-plugin

Dynamic Registration of PluginMap

Open
#187 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
6.1k
Forks
511
Avg merge
22h 47m
Merged PRs (30d)
4

Description

I'd like to build an app that fetches rows of data from a database and then invokes some generic callback of the form `HandleRows(ctx, rows...) error`. It'd be nice to have a single binary for the primary app, but the behavior of the app is dependent upon the plugin that is loaded for the interface that defines the `HandleRows` method.

Do you guys have any examples of how to dynamically register a PluginMap based on module registration from within the module and within the host client?

Essentially the workflow I'm looking for is this:

1. Developer authors a plugin and compiles it into a `.so` file.
2. When the host client app starts up it looks for a configurable plugin directory (e.g. `~/.myapp/plugins`).
3. The plugin module registers its dispensable plugins by adding itself to the PluginMap.
4. The host client app invokes the shared interface from the plugin.

There will only ever really be one plugin loaded at a time in my use case, but the plugins behavior will define what functionality gets invoked when `HandleRows(ctx, rows...)` is called.

I'm using this approach to try and build a generic outbox processing mechanism as part of an [outbox pattern](https://microservices.io/patterns/data/transactional-outbox.html) implementation. The way outbox events are handled across apps will differ, but the processing of the events is the same regardless of what you do with them. I thought about using AWS lambdas or something similar to achieve this, but the `go-plugin` approach seems like it could be a more native approach and wouldn't have the downsides of lambda invocation and the latency/cost associated with that.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.