Skip to content

Commit 97e6650

Browse files
committed
added autorouting to documentation
1 parent 0560d12 commit 97e6650

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ use GuzzleHttp\Client;
155155
use GuzzleHttp\Handler\CurlHandler;
156156
use GuzzleHttp\HandlerStack;
157157
use GuzzleHttp\Middleware;
158-
use Laudis\Neo4j\Network\Bolt\BoltInjections;use Laudis\Neo4j\Network\Http\HttpInjections;
158+
use Laudis\Neo4j\Network\Bolt\BoltInjections;
159+
use Laudis\Neo4j\Network\Http\HttpInjections;
159160

160161
$client = Laudis\Neo4j\ClientBuilder::create()
161162
->addHttpConnection('backup', 'http://neo4j:password@localhost', HttpInjections::create()->withClient(static function () {
@@ -169,6 +170,31 @@ $client = Laudis\Neo4j\ClientBuilder::create()
169170

170171
Wrapping the injections in a callable will enforce lazy initialization.
171172

173+
### Clusters and routing
174+
175+
Cluster support is always available when directly connecting to the responsible servers. If you do not need to fine tune these connections, autorouting is available for bolt connections:
176+
177+
```php
178+
use Laudis\Neo4j\Network\Bolt\BoltInjections;
179+
180+
$client = Laudis\Neo4j\ClientBuilder::create()
181+
->addBoltConnection(
182+
'main',
183+
'http://neo4j:password@any-server-with-routing-information',
184+
BoltInjections::create()->withAutoRouting(true)
185+
)
186+
->addBoltConnection('backup', 'http://neo4j:password@non-replicated-server')
187+
->setDefaultConnection('main')
188+
->build();
189+
190+
$client->run('RETURN 1'); // will run over a random follower found in the routing table
191+
$client->run('MERGE (x:Y {z: 0)'); //will run over a random leader found in the routing table
192+
$client->run('RETURN 1', [], 'backup'); //will run over the non replicated server
193+
$client->run('RETURN 1', [], 'main'); //will be autorouted
194+
```
195+
196+
NOTE: http cluster support will be available in the next minor release and will have practically the same api.
197+
172198
## Final Remarks
173199

174200
### Filosophy

0 commit comments

Comments
 (0)