Apollo C++ Client
C++ client for Apollo Configuration Center
Loading...
Searching...
No Matches
apollo::client::ApolloClient Class Referenceabstract

Interface for the Apollo configuration center client. More...

#include <apollo_client.h>

Public Member Functions

virtual ~ApolloClient ()=default
 Virtual destructor to ensure proper cleanup in derived classes.
virtual void startLongPolling (int long_polling_interval_ms=long_poller_interval_default)=0
 Starts a long polling thread for configuration updates.
virtual void stopLongPolling ()=0
 Stops the long polling thread.
virtual Configures getConfigures (const NamespaceType &s_namespace)=0
 Retrieves configuration values from the ApolloClient cache.
virtual void setNotificationsListener (NotificationCallbackPtr notificationCallback)=0
 Sets a callback for configuration change notifications.

Detailed Description

Interface for the Apollo configuration center client.

This interface allows applications to access and monitor configuration data stored in Apollo Configuration Center. It provides methods for retrieving configurations and receiving notifications when configuration changes occur.

Member Function Documentation

◆ getConfigures()

virtual Configures apollo::client::ApolloClient::getConfigures ( const NamespaceType & s_namespace)
pure virtual

Retrieves configuration values from the ApolloClient cache.

Returns the configuration key-value pairs for the specified namespace. The values are retrieved from the ApolloClient's local cache, which is updated by the long polling thread.

Parameters
s_namespaceThe namespace to retrieve configurations from
Returns
A map of configuration key-value pairs
Note
Returns an empty map if the namespace is not in the configured namespaces list or if the namespace has no configurations. If long polling has not been started, this will return only the initial configuration loaded at ApolloClient creation.

◆ setNotificationsListener()

virtual void apollo::client::ApolloClient::setNotificationsListener ( NotificationCallbackPtr notificationCallback)
pure virtual

Sets a callback for configuration change notifications.

Registers a callback function that will be invoked whenever configuration changes are detected. The callback receives the namespace that changed, the old and new configurations, and a detailed list of changes (added, modified, deleted items).

Parameters
notificationCallbackA weak pointer to the callback function. Using a weak pointer ensures that the client doesn't hold a reference to an object that might be destroyed.
Note
It's recommended to set the callback before calling startLongPolling() to avoid missing any changes. The callback should be thread-safe as it's called from a background thread. This function can be called repeatedly to change the callback.

◆ startLongPolling()

virtual void apollo::client::ApolloClient::startLongPolling ( int long_polling_interval_ms = long_poller_interval_default)
pure virtual

Starts a long polling thread for configuration updates.

Starts a background thread that periodically polls the Apollo server for configuration updates. When changes are detected, the notification callback (if set) will be invoked from the background thread.

Parameters
long_polling_interval_msInterval in milliseconds between polling requests. If set to 0 or negative, long polling thread will not be started and configuration will not be updated.
Note
This method is non-blocking; it starts the polling thread and returns immediately.

◆ stopLongPolling()

virtual void apollo::client::ApolloClient::stopLongPolling ( )
pure virtual

Stops the long polling thread.

Stops the background polling thread if it's running. After calling this method, no further configuration updates will be received and no callbacks will be triggered. This method blocks until the polling thread has terminated.


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