23_bolt_server

command
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 13 Imported by: 0

README

Example 23 — Bolt v5 server round-trip

What it demonstrates

GoGraph speaking the Bolt v5 wire protocol end to end: it starts the embedded bolt/server over an in-memory graph, connects the official neo4j-go-driver/v5 as a real client, runs a Cypher query through a session, prints the returned rows, and shuts the server down cleanly with no goroutine left behind.

Domain / scenario

A trivial social graph: three :Person nodes — Alice, Bob, and Carol — each with a name property. The nodes are seeded in process through the engine before the server starts. A Bolt client then issues MATCH (n:Person) RETURN n.name AS name ORDER BY name over the network and reads the ordered names back off the wire.

The listener binds to 127.0.0.1:0, so the kernel assigns a free port; the client discovers it from ln.Addr(). The server is fully compatible with neo4j-go-driver/v5 and cypher-shell.

How to run

go run ./examples/23_bolt_server

Expected output

The query result — the three ordered names and the row count — is deterministic. The listener address on the first line varies per run because the port is OS-assigned.

GoGraph Bolt v5 server listening on 127.0.0.1:55710
Compatible with neo4j-go-driver v5 and cypher-shell.
Client query: MATCH (n:Person) RETURN n.name AS name ORDER BY name
Returned 3 rows:
  name = Alice
  name = Bob
  name = Carol
Server shut down cleanly.

The 127.0.0.1:55710 port is illustrative; every run prints a different OS-assigned port.

Key APIs

  • bolt/server.NewServer / Server.Serve / Server.Shutdown — start the Bolt v5 TCP server on a listener and tear it down gracefully, draining every per-connection goroutine.
  • bolt/server.Options — bound concurrent connections (MaxConnections) and set the per-connection idle deadline (ConnTimeout).
  • cypher.NewEngine / Engine.RunInTxAny — build the query engine over an in-memory graph and seed :Person nodes via an in-process write transaction.
  • graph/lpg.New — the in-memory labelled property graph the engine serves.
  • github.com/neo4j/neo4j-go-driver/v5/neo4j — the official Bolt client: NewDriverWithContext, NewSession, Session.Run, Result.Collect, and clean Close on teardown.

Further reading

Documentation

Overview

Example 23_bolt_server starts a GoGraph Bolt v5 server backed by an in-memory labelled property graph, then drives a full client round-trip against it with the official neo4j-go-driver/v5.

The example seeds a handful of :Person nodes through the engine, brings the server up on a kernel-assigned 127.0.0.1:0 port, connects a real Bolt client, runs a Cypher MATCH query over a session, and prints the rows the server returns. It then closes the client, shuts the server down gracefully, and drains the serve goroutine so no goroutine leaks — the same teardown discipline as bolt/server/example_test.go.

Sample output: run `go run ./examples/23_bolt_server` and capture the stdout. The query result (the ordered list of names) is deterministic and serves as the regression baseline a future change should preserve; the listener address line varies per run because the port is OS-assigned.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL