Github   Telegram
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
dynamic_config::Source Class Referencefinal

A client for easy dynamic config fetching in components. More...

#include <userver/dynamic_config/source.hpp>

Public Types

using EventSource = concurrent::AsyncEventSource< const Snapshot & >
 

Public Member Functions

 Source (impl::StorageData &storage)
 
 Source (const Source &)=default
 
Sourceoperator= (const Source &)=default
 
Snapshot GetSnapshot () const
 
template<typename Key >
VariableSnapshotPtr< KeyGetSnapshot (Key key) const
 
template<typename Key >
VariableOfKey< KeyGetCopy (Key key) const
 
template<typename Class >
concurrent::AsyncEventSubscriberScope UpdateAndListen (Class *obj, std::string_view name, void(Class::*func)(const dynamic_config::Snapshot &config))
 
EventSourceGetEventChannel ()
 

Detailed Description

A client for easy dynamic config fetching in components.

After construction, dynamic_config::Source can be copied around and passed to clients or child helper classes.

Usually retrieved from components::DynamicConfig component.

Typical usage:

namespace myservice::smth {
namespace {
int ParseRuntimeCfg(const dynamic_config::DocsMap& docs_map) {
return docs_map.Get("SAMPLE_INTEGER_FROM_RUNTIME_CONFIG").As<int>();
}
} // namespace
int Component::DoSomething() const {
// Getting a snapshot of dynamic config.
const auto runtime_config = config_.GetSnapshot();
return runtime_config[kMyConfig];
}
} // namespace myservice::smth
Examples
components/component_sample_test.hpp.

Definition at line 64 of file source.hpp.

Member Typedef Documentation

◆ EventSource

Definition at line 66 of file source.hpp.

Constructor & Destructor Documentation

◆ Source()

dynamic_config::Source::Source ( impl::StorageData &  storage)
explicit

For internal use only. Obtain using components::DynamicConfig or dynamic_config::StorageMock instead.

Member Function Documentation

◆ GetCopy()

template<typename Key >
VariableOfKey< Key > dynamic_config::Source::GetCopy ( Key  key) const
inline

Definition at line 84 of file source.hpp.

◆ GetSnapshot()

template<typename Key >
VariableSnapshotPtr< Key > dynamic_config::Source::GetSnapshot ( Key  key) const
inline

Definition at line 79 of file source.hpp.

◆ UpdateAndListen()

template<typename Class >
concurrent::AsyncEventSubscriberScope dynamic_config::Source::UpdateAndListen ( Class *  obj,
std::string_view  name,
void(Class::*)(const dynamic_config::Snapshot &config)  func 
)
inline

Subscribes to dynamic-config updates using a member function, named OnConfigUpdate by convention. Also immediately invokes the function with the current config snapshot.

Definition at line 93 of file source.hpp.


The documentation for this class was generated from the following file: