Bolt Routing Driver, the Bolt+Routing Neo4j driver that supports clustering for Elixir using bolt_sips.
It means that you can send a read query to the driver and using one of the load balancing strategies will forward it to a chosen core.
# We need to specify when we are sending a write query that will require to be sent to the leader
iex> Bolt.RoutingDriver.write_query("CREATE (n:Person { name: 'Adrian' })")
[debug] [Bolt.RoutingDriver] localhost:7687 query...
{:ok,
%{
stats: %{"labels-added" => 1, "nodes-created" => 1, "properties-set" => 1},
type: "w"
}}
# Then we can send read queries, that will be executed in a different follower each time
iex> Bolt.RoutingDriver.read_query("MATCH (n:Person {name: 'Adrian'}) RETURN n")
[debug] [Bolt.RoutingDriver] localhost:7688 query...
{:ok,
[
%{
"n" => %Bolt.Sips.Types.Node{
id: 0,
labels: ["Person"],
properties: %{"name" => "Adrian"}
}
}
]}
# Now, it will run in a different follower
iex> Bolt.RoutingDriver.read_query("MATCH (n:Person {name: 'Eduard'}) RETURN n")
[debug] [Bolt.RoutingDriver] localhost:7689 query...
{:ok, []}
The package can be installed as:
def deps do
[{:bolt_routing_driver, git: "https://github.com/Badiapp/bolt-routing-driver"}]
end
def application do
[applications: [:bolt_routing_driver], mod: {Bolt.RoutingDriver.Application, []}]
end
Edit your config/config.exs
and set the entry URL, and any bolt_sips config that you want to change, for example:
config :bolt_sips, Bolt,
url: "<YOUR ENTRY URL>"
# Any bolt_sips config that you want to change
bolt_sips: [
basic_auth: [
username: "<YOUR USERNAME>",
password: "<YOUR PASSWORD>"
],
pool_size: 10
]
Clone the repository
git@github.com:Badiapp/bolt-routing-driver.git
Install dependencies
cd bolt-routing-driver
mix deps.get
- Florin T.Patrascu (@florinpatrascu), for implementing the Neo4j driver in Elixir: florinpatrascu/bolt_sips
- Adrián Pino (@adrpino), Eduard López (@eduardlopez) and Xavier Fontrodona (@xfontro), for inspiring and helping to develop the first implementation of this routing driver.