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
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 how to do it in your own project:
// Starting the Event Loop
await Endpoint.startEventLoop();
// Handling Store Events
const context = Endpoint.connection().context('CONTEXT_ID');
const channel = await context.stores.subscribeForStoreEvents();
channel.on('storeCreated', (data) => console.log(data))
// Handling File Events
const channel = await context.store('STORE_ID').subscribeForFileEvents();
channel.on('storeFileCreated', (data) => console.log(data))
For JavaScript reference go here.