Skip to content

Instantly share code, notes, and snippets.

@alisuleymantopuz
Last active July 14, 2022 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alisuleymantopuz/b1a5759bea058f0c47ef0db7f1aac07c to your computer and use it in GitHub Desktop.
Save alisuleymantopuz/b1a5759bea058f0c47ef0db7f1aac07c to your computer and use it in GitHub Desktop.
A gist to check how ravenDb changes api push notification service works
// 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