PrivMX DOCS
Version 2.5/Kvdbs

Listening for Changes

Listening for events related to KVDBs and updating your app's state accordingly will allow you to build e.g., instant mapping features.

Types of Events

The lists below outline all the event types available in KVDBs and entries in PrivMX.

KVDB events:

  • kvdbCreated - triggers when a new KVDB is created in your Context
  • kvdbDeleted - triggers when a KVDB is deleted from your Context
  • kvdbUpdated - triggers when a KVDB is updated
  • kvdbStatsChanged - triggers when an entry is created to a KVDB or an entry has been deleted

Entries events:

  • kvdbNewEntry - triggers when an entry was created in a KVDB
  • kvdbEntryDeleted triggers when an entry was deleted from a KVDB
  • kvdbEntryUpdated - triggers when an entry was updated

Handling KVDB and Entries Events

Before receiving Events, your application has to start an event loop and subscribe to a specific channel. Afterwards you can setup a listener.

Here is an example how to do it in your own project:

// handle events
core::EventQueue eventQueue {core::EventQueue::getInstance()};
std::thread t([&](){
    while(true) {
        core::EventHolder event = eventQueue.waitEvent();
        std::cout << "onEvent: " << event.type() << std::endl;
        std::cout << event.toJSON() << std::endl;
        if(core::Events::isLibBreakEvent(event)) {
            // way to stop Event listener
            break;
        }
    }
});
t.detach();
// subscribe for KVDBs general events
kvdbApi.subscribeForKvdbEvents();

// subscribe for KVDBs general events
kvdbsApi.subscribeForKvdbEvents();

We use cookies on our website. We use them to ensure the proper functioning of the site and, if you agree, for purposes we set, such as analytics or marketing.

On this page