Last active
July 14, 2022 20:31
-
-
Save alisuleymantopuz/b1a5759bea058f0c47ef0db7f1aac07c to your computer and use it in GitHub Desktop.
A gist to check how ravenDb changes api push notification service works
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Push Notifications for tracking changes on RavenDB entities Explained | |
// The Changes API is a Push Notifications service, | |
// that allows a RavenDB Client to receive messages from a RavenDB Server regarding events that occurred on the server. | |
// Being able to reach your visitors without any kind of effort | |
// server -> request -> push service -> message arrives | |
// capabilities of push notifications | |
// Web Push Notifications are used for simple tasks like alerting a user about upcoming sales or events. | |
// They display an icon and a few lines of text that the user can then click to open and | |
// go to a specific destination on your site | |
import { DocumentStore } from "./node_modules/ravendb/dist/Documents/DocumentStore.js" | |
import * as fs from "fs"; | |
// load certificate and prepare authentication options | |
const authOptions = { | |
certificate: fs.readFileSync("x.pfx"), | |
type: "pfx", | |
password: "<pass>" | |
}; | |
const store = new DocumentStore(['<url>'], 'northwind', authOptions); | |
store.initialize(); | |
console.info('initialized.'); | |
const changes = store.changes(); | |
await changes.ensureConnectedNow(); | |
const session = store.openSession(); | |
const allDocsChanges = changes.forAllDocuments() | |
.on("data", async change => { | |
const product = await session.load(change.id, 'Products'); | |
const response = { | |
latestVersion: product, | |
change | |
}; | |
console.log(response); | |
}) | |
.on("error", err => { | |
// handle error | |
}); | |
try { | |
// application code here | |
} finally { | |
// dispose changes after use | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment