flowchartsman opened a new pull request #8467:
URL: https://github.com/apache/pulsar/pull/8467
### Motivation
The pulsar go functions SDK has no access to user config outside of the
function context, which is only accessible from inside the function handler
itself (i.e. once processing has started). This is a somewhat awkward access
method when it comes to user configuration values which might be used to
initialize a persistent connection to a database or other service, since it
would require a largely-superfluous check for the initialization and related
configuration values in every run of the function, when it's only required once
at startup.
### Modifications
Two global methods have been provided to access the user config map and
individual values from it, by key.
### Verifying this change
This change is predicated on the changes (#8132) made towards solving
#8216, and will need to be tested in conjunction with them, however a very
similar example should suffice:
```go
package main
import (
"context"
"fmt"
log "github.com/apache/pulsar/pulsar-function-go/logutil"
"github.com/apache/pulsar/pulsar-function-go/pf"
)
func contextFunc(ctx context.Context) {
if fc, ok := pf.FromContext(ctx); ok {
log.Infof("function ID is:%s, ", fc.GetFuncID())
log.Infof("function version is:%s\n", fc.GetFuncVersion())
for k := range fc.GetUserConfMap() {
log.Infof("Config %q -> \"%v\"", k,
fc.GetUserConfValue(k))
}
}
}
func main() {
conf := pf.GetUserConfig()
for k := range conf {
fmt.Printf("Config %q -> \"%v\"\n", k, fc.GetUserConfValue(k))
}
pf.Start(contextFunc)
}
```
### Does this pull request potentially affect one of the following parts:
*If `yes` was chosen, please highlight the changes*
- Dependencies (does it add or upgrade a dependency): (yes / no)
- The public API: (yes)
- Two new global methods are added to the Pulsar Functions for Go SDK,
`GetUserConfig()` and `GetUserConfigValue(key string)`
- The schema: (no)
- The default values of configurations: (no)
- The wire protocol: (no)
- The rest endpoints: (no)
- The admin cli options: (no)
- Anything that affects deployment: (don't know)
#### Public API
This adds two new global methods to the Pulsar Functions for Go SDK,
mentioned above
### Documentation
- Does this pull request introduce a new feature? (yes)
- If yes, how is the feature documented? (not applicable)
- If a feature is not applicable for documentation, explain why?
- godoc will suffice
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]