Poco::MongoDB

class TopologyChangeNotification

Library: MongoDB
Package: MongoDB
Header: Poco/MongoDB/TopologyChangeNotification.h

Description

Notification sent when MongoDB replica set topology changes.

This notification is posted to Poco::NotificationCenter::defaultCenter() whenever a topology change is detected during topology refresh.

The notification contains a Dynamic::Struct with the following members: - replicaSet (std::string): The replica set name - timestamp (Poco::Int64): Timestamp in seconds since Unix epoch - topologyType (std::string): Human-readable topology type

(e.g., "Replica Set (with Primary)", "Single Server", etc.)

- changeDescription (std::string): Brief description of what changed

(e.g., "Primary elected: mongo1:27017", "Servers: 2 -> 3")

Example usage:

class MyClass
{
public:
    MyClass()
    {
        // Register observer
        NotificationCenter::defaultCenter().addNObserver(
            *this,
            &MyClass::handleTopologyChange
        );
    }

    ~MyClass()
    {
        // Unregister observer
        NotificationCenter::defaultCenter().removeNObserver(
            *this,
            &MyClass::handleTopologyChange
        );
    }

    void handleTopologyChange(const AutoPtr<TopologyChangeNotification>& pNf)
    {
        const auto& data = pNf->data();

        std::string rsName = data["replicaSet"];
        Poco::Int64 timestamp = data["timestamp"];
        std::string topologyType = data["topologyType"];
        std::string changeDesc = data["changeDescription"];

        // Handle topology change...
    }
};

Inheritance

Direct Base Classes: Poco::Notification

All Base Classes: Poco::Notification, Poco::RefCountedObject

Member Summary

Member Functions: data, name

Inherited Functions: duplicate, name, referenceCount, release

Types Aliases

Ptr

using Ptr = AutoPtr < TopologyChangeNotification >;

Constructors

TopologyChangeNotification inline

TopologyChangeNotification(
    const Dynamic::Struct < std::string > & data
);

Creates a TopologyChangeNotification with the given data.

Member Functions

data inline

const Dynamic::Struct < std::string > & data() const;

Returns the topology change data.

name virtual inline

std::string name() const override;

Returns the notification name.