Store Events in Real-Time
Events play a crucial role in modern applications, allowing them to instantly respond to changes in stored data. Monitoring and reacting to file and store-related events, such as the creation, modification, or deletion of files, is essential for maintaining up-to-date records, triggering workflows, and ensuring synchronization across various parts of the system.
Types of Events
Store events:
storeCreated
- triggers when a new Store is created in your ContextstoreDeleted
- triggers when a Store is deleted from your ContextstoreUpdated
- triggers when a Store is updated in your ContextstoreStatsChanged
- triggers when a file is created or deleted from a Store
File events:
storeFileCreated
- triggers when a file is uploaded to a StorestoreFileDeleted
- triggers when a file is deleted from a StorestoreFileUpdated
- triggers when a file is updated in a Store
Handling Store Events
Info
The sample code on this page is based on the same assumptions mentioned in Managing Stores.
Before receiving Events, your application must first start an event loop and subscribe to a specific channel. Afterwards you can setup a listener.
Here is an example of 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;
}
});
t.detach();
// subscribe for Stores general events
storesApi.subscribeForStoreEvents();
// subscribe for particular Store events
storesApi.subscribeForFileEvents(storeId);