npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

neo4j-ha-bolt-driver

v1.2.3

Published

Official Neo4j Bolt driver wrapped in a layer of High Availability

Downloads

13

Readme

Neo4j High Availability Bolt Javascript Driver

Neo4j cluster session and transparent failover

About

This driver is a wrapper over the official Neo4j bolt driver and adds a layer of High Availability and transparent failovers

How to install

npm i --save neo4j-ha-bolt-driver

Quick example

const servers = [
    ['http://127.0.0.1:7474', 'bolt://127.0.0.1:7687'],
    ['http://127.0.0.1:7475', 'bolt://127.0.0.1:7688']
];

const auth = { user: 'neo4j', pass: 'password' };
const strategy = Neo4jHA.HAStrategies.roundRobin;
const rwConfig = Neo4jHA.HAReadWrite.masterReadWriteSlaveRead;
const checkInterval = 500;

console.log('connecting...');
const driver = new Neo4jHA(servers, { auth, strategy, rwConfig, checkInterval }, () => {
    console.log('ready');
    let session;
  
    // we get a session and we tell the driver that we will berform at least one write
    // the strategy is Round Robin but because we want to write 
    // and the read/write config is set to masterReadWriteSlaveRead (only master can write) 
    // this means that it will get a session to the master 
    session = driver.session(true);
    
    // don't forget to close sessions when you're done with them
    session.close();
    
    // now we request a read-only  session, so all servers are eligible for conenctions
    // the first server in the list is chosen
    session = driver.session(false);
    session.close();
    
    // requesting another read-only session will choose the second server
    // because of the Round Robin 
    session = driver.session();
    session.close();
}

// when you are done with the driver, just close it
driver.close();

Enums

HAStrategies

  • random: It will pick a random server from the pool
  • roundRobin: It will round robin through the server pool
  • nearest: It will pick the server with the lowest latency

HAReadWrite

  • masterOnly: Master will be the only queried server
  • masterWriteOnlySlaveReadOnly: Master is write-only and slaves are read-only
  • masterReadWriteSlaveRead: Master is read-write and slaves are read-only
  • all: All servers are read-write
  • Custom HAReadWrite Structure
{
        master: { read: Boolean, write: Boolean },
        slave: { read: Boolean, write: Boolean }
}

Status

  • error (-2): Server is returning an error in the HA check
  • unknown (-1): Server is in an unknown state
  • down ( 0): Server is unreachable
  • up ( 1): Server is in the cluster

ServerType

  • unknown ( 0): Server is in an unknown state
  • slave ( 1): Server is a slave
  • master ( 2): server is master

Instantiating a driver

const driver = new Neo4jHA(serverList, options, readyCallback);

Where:

  • serverList: is an array of
    • [HTTP URL, BOLT URL]
    • {bolt: Bolt URL, url: HTTP URL, auth: {user, pass}}
  • options:
    • auth: {user, pass} - for all the connections
    • strategy: HAStrategies
    • rwConfig: HAReadWriteConfig
    • neo4jDriverOptions: options passed on the the raw neo4j bolt driver
    • checkInterval: interval to check servers availability
    • retryOnError: number of times to retry the query until the error is surfaced in callback
    • badConnectionsCountAsErrors: true if a server connection error is counted as an error
  • readyCallback: callback when all servers status is known

Usage

const session = driver.session(writeLock[, rwConfig, strategy]);

Where:

  • writeLock: Boolean - Tell the driver ifif there will ve any writes in the session
  • rwConfig: custom HAReadWriteConfig for that session
  • strategy: custom HAStrategies for that session

License

License can be found here