Fetched handler

2 minute readData analytics

You can identify when CloudBees Feature Management SDK has loaded configuration from local storage or network by adding the onConfigurationFetched handler to RoxOptions.

Examples

The following are examples of code in different SDKs that add the onConfigurationFetched handler:

Swift
Android
React Native
JavaScript
Node.js
JavaScript SSR
JVM
.NET
Python
Go
Ruby
PHP
C
C++
let options = ROXOptions() options.onConfigurationFetched = { (result: RoxFetcherResult) -> Void in print(result) }; ROX.setup(withKey:appKey, options:options)
RoxOptions options = new RoxOptions.Builder() .withConfigurationFetchedHandler(new ConfigurationFetchedHandler() { @Override public void onConfigurationFetched(FetcherResults results) { Logger.info("Got Rollout configuration"); } }).build(); Rox.setup(this.getApplication(), options);
const configurationFetchedHandler = fetcherResults => { console.log(fetcherResults); }; const options = { configurationFetchedHandler : configurationFetchedHandler }; Rox.setup(appKey, options);
const configurationFetchedHandler = fetcherResults => { console.log(fetcherResults); }; const options = { configurationFetchedHandler : configurationFetchedHandler }; Rox.setup(appKey, options);
const configurationFetchedHandler = fetcherResults => { console.log(fetcherResults); }; const options = { configurationFetchedHandler : configurationFetchedHandler }; Rox.setup(appKey, options);
import {Rox} from 'rox-ssr'; const configurationFetchedHandler = fetcherResults => { console.log(fetcherResults); }; const options = { configurationFetchedHandler : configurationFetchedHandler }; Rox.setup(appKey, options);
RoxOptions options = new RoxOptions.Builder() .withConfigurationFetchedHandler(new ConfigurationFetchedHandler() { @Override public void onConfigurationFetched(FetcherResults results) { Logger.info("Got Rollout configuration"); } }).build(); Rox.setup(ROLLOUT_KEY, options);
var options = new RoxOptions(new RoxOptions.RoxOptionsBuilder { ConfigurationFetchedHandler = (sender, e) => { Console.WriteLine("Got Rollout configuration"); } }); Rox.setup(ROLLOUT_KEY, options);
from my_container import MyContainer from rox.server.rox_server import Rox from rox.server.rox_options import RoxOptions my_container = MyContainer() Rox.register('test', my_container) # setup configuration_fetched_handler in the options object options = RoxOptions( configuration_fetched_handler=lambda o: print("applied-from=%s creation-date=%s has-changes=%s error=%s" % (o.fetcher_status , o.creation_date , o.has_changes , o.error_details) ) ) cancel_event = Rox.setup(ROLLOUT_KEY, options).result();
import ( "github.com/rollout/rox-go/v5/server" "github.com/rollout/rox-go/v5/core/model" ) type Container struct {} var flags = &Container {} rox.Register('test', flags) options := server.NewRoxOptions(server.RoxOptionsBuilder { ConfigurationFetchedHandler: func(e *model.ConfigurationFetchedArgs) { fmt.Println("applied-from=", e.FetcherStatus ,"creation-date=", e.CreationDate,"has-changes=", e.HasChanges, "errors=", e.ErrorDetails)}, }) <- rox.Setup(ROLLOUT_KEY, options)
require_relative 'container' require 'rox/server/rox_server' require 'rox/server/rox_options' configuration_fetched_handler = proc do |e| puts "applied-from=#{e.fetcher_status} creation-date=#{e.creation_date} has-changes=#{e.has_changes} error=#{e.error_details}" end container = Container() Rox::Server::RoxServer.register('', container) # setup configuration_fetched_handler in the options object option = Rox::Server::RoxOptions.new( configuration_fetched_handler: configuration_fetched_handler ) Rox::Server::RoxServer.setup(<ROLLOUT_KEY>, option).join
use Rox\Server\Rox; use Rox\Server\RoxOptions; use Rox\Server\RoxOptionsBuilder; use Rox\Core\Configuration\ConfigurationFetchedArgs; use Rox\Core\Configuration\FetcherStatus; use Rox\Core\Configuration\FetcherError; $roxOptionsBuilder = (new RoxOptionsBuilder()) ->setConfigurationFetchedHandler(function (ConfigurationFetchedArgs $args) { if ($args != null) { echo "applied-from=" . $args->getFetcherStatus(); // FetcherStatus echo " creation-date=" . $args->getCreationDate(); echo " has-Changes=" . $args->isHasChanges(); echo " error=" . $args->getErrorDetails(); // FetcherError } }) Rox::setup(ROLLOUT_KEY, new RoxOptions($roxOptionsBuilder));
void configuration_fetched_handler(void *target, RoxConfigurationFetchedArgs *args) { if (args != NULL) { printf("applied-from=%d", args->fetcher_status); printf(" creation-date=%s", args->creation_date); printf(" has-Changes=%s", args->has_changes ? "yes" : "no"); printf(" error=%d", args->error_details); } } int main(int argc, char **argv) { RoxOptions *options = rox_options_create(); rox_options_set_configuration_fetched_handler(options, NULL, &configuration_fetched_handler); rox_setup(DEFAULT_API_KEY, options); rox_shutdown(); }
class ConfigurationFetchedHandler : public Rox::ConfigurationFetchedHandler { public: explicit ConfigurationFetchedHandler() {} public: void ConfigurationFetched(Rox::ConfigurationFetchedArgs *args) override { if (args != NULL) { printf("applied-from=%d", args->fetcher_status); // FetcherStatus enum printf(" creation-date=%s", args->creation_date); printf(" has-Changes=%s", args->has_changes ? "yes" : "no"); printf(" error=%d", args->error_details); // FetchError enum } } }; int main(int argc, char **argv) { ConfigurationFetchedHandler configurationFetchedHandler = ConfigurationFetchedHandler(); Rox::Options *options = Rox::OptionsBuilder() .SetConfigurationFetchedHandler(&configurationFetchedHandler) .Build(); Rox::Setup(DEFAULT_API_KEY, options); Rox::Shutdown(); }

FetcherResult information

The FetcherResult has the following information regarding the actual fetch:

  • fetcherStatus - an enum that identifies which configuration was fetched (from the network, from local storage, an error occurred)

  • creationDate - Date of configuration creation

  • errorDetails - The description of the error if one exists

  • hasChanges - Does this configuration differ from the one it is replacing